Changeset 551
- Timestamp:
- 09/01/08 21:07:14 (4 months ago)
- Files:
-
- Mika/trunk/core-vm/include/clazz.h (modified) (3 diffs)
- Mika/trunk/core-vm/include/loading.h (modified) (1 diff)
- Mika/trunk/core-vm/include/package.h (modified) (2 diffs)
- Mika/trunk/core-vm/src/classfile/clazz.c (modified) (3 diffs)
- Mika/trunk/core-vm/src/heap/collector.c (modified) (6 diffs)
- Mika/trunk/core-vm/src/native/java/lang/ClassLoader.c (modified) (3 diffs)
- Mika/trunk/core-vm/src/vm/checks.c (modified) (4 diffs)
- Mika/trunk/core-vm/src/vm/core-classes.in (modified) (1 diff)
- Mika/trunk/core-vm/src/vm/loading.c (modified) (9 diffs)
- Mika/trunk/core-vm/src/vm/package.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
Mika/trunk/core-vm/include/clazz.h
r538 r551 34 34 #define _CLAZZ_H 35 35 36 #include "package.h" 36 37 #include "wonka.h" 37 38 #include "hashtable.h" … … 72 73 w_thread resolution_thread; /* thread which is busy with this class */ 73 74 /* (unstable class states only) */ 75 w_package package; /* runtime package of which this class is a member */ 74 76 75 77 /* Information available in states CLAZZ_STATE_SUPERS_LOADED and higher */ … … 338 340 extern w_hashtable system_unloaded_class_hashtable; 339 341 342 extern w_hashtable system_package_hashtable; 343 340 344 /* 341 345 ** Get a copy of a reference field of a class Mika/trunk/core-vm/include/loading.h
r372 r551 124 124 ** Given an instance 'l' of java.lang.ClassLoader, return a pointer to the 125 125 ** w_Hashtable which holds a pointer to a w_UnloadedClazz structure for each 126 ** class which has been marked as loadable by th eis loader but has not yet126 ** class which has been marked as loadable by this loader but has not yet 127 127 ** been loaded. 128 128 ** If 'l' is null, system_unloaded_class_hashtable is returned. 129 129 */ 130 130 #define loader2unloaded_classes(l) ((l) ? getWotsitField((l), F_ClassLoader_unloaded_classes) :system_unloaded_class_hashtable) 131 132 /* 133 ** Given an instance 'l' of java.lang.ClassLoader, return a pointer to the 134 ** w_Hashtable which holds a pointer to a w_Package structure for each 135 ** package for which at least one class which has been loaded by this loader. 136 ** If 'l' is null, system_package_hashtable is returned. 137 */ 138 #define loader2packages(l) ((l) ? getWotsitField((l), F_ClassLoader_packages) :system_package_hashtable) 131 139 132 140 /* Mika/trunk/core-vm/include/package.h
r543 r551 38 38 w_string name; /* Package name, e.g. java.lang */ 39 39 char *label; /* null-terminated C string beginning "pack" */ 40 w_flags flags; /* reserved*/40 w_flags flags; /* not yet used */ 41 41 w_instance loader; /* the ClassLoader that defined this package */ 42 42 } w_Package; … … 54 54 void destroyPackage(w_package); 55 55 56 /** 57 ** Get the runtime package corresponding to the named class, creating it 58 ** if it does not already exist. 59 */ 60 w_package getPackageForClazz(w_clazz clazz, w_instance loader); 61 62 /* 63 ** Function called as soon as the system class loader has been created, 64 ** to back-patch all existing packages to have loader = systemClassLoader. 65 */ 66 void patchPackages(); 67 56 68 #endif /* _PACKAGE_H */ 57 69 Mika/trunk/core-vm/src/classfile/clazz.c
r538 r551 74 74 /* 75 75 ** Each classloader has associated with it a hashtable of loaded classes 76 ** and one of unloaded classes . For the "primordial" class loader these are77 ** static items.76 ** and one of unloaded classes, plus a hashtable of packages it has loaded. 77 ** For the "primordial" class loader these are static items. 78 78 */ 79 79 80 80 w_hashtable system_loaded_class_hashtable; 81 81 w_hashtable system_unloaded_class_hashtable; 82 w_hashtable system_package_hashtable; 82 83 83 84 /* … … 1778 1779 1779 1780 set_classname(clazz); 1781 getPackageForClazz(clazz, loader); 1780 1782 1781 1783 clazz->resolution_thread = NULL; … … 1983 1985 woempa(7, "Releasing temp.inner_class_info\n"); 1984 1986 releaseMem(clazz->temp.inner_class_info); 1987 } 1988 1989 if (clazz->resolution_monitor) { 1990 woempa(7, "Releasing resolution_monitor\n"); 1991 x_monitor_delete(clazz->resolution_monitor); 1992 releaseMem(clazz->resolution_monitor); 1985 1993 } 1986 1994 } Mika/trunk/core-vm/src/heap/collector.c
r495 r551 2 2 * Parts copyright (c) 2001, 2002, 2003 by Punch Telematix. All rights * 3 3 * reserved. * 4 * Parts copyright (c) 2004, 2005, 2006, 2007 by Chris Gray,*4 * Parts copyright (c) 2004, 2005, 2006, 2007, 2008 by Chris Gray, * 5 5 * /k/ Embedded Java Solutions. All rights reserved. * 6 6 * * … … 337 337 338 338 /* 339 ** Release the memory held by a w_UnloadedClazz in a class loader's unload 340 ** class hashtable. We shouldn't really need to do this - by the time the 341 ** class loader is collected the table should be empty. Strange ... 339 ** Release the memory held by a w_UnloadedClazz in a class loader's unloaded 340 ** class hashtable. 342 341 */ 343 342 static void trashUnloadedClasses(w_word key, w_word value, void *dummy1, void*dummy2) { … … 346 345 woempa(7, "trashing %K (%d references)\n", clazz, value); 347 346 releaseMem(clazz); 347 } 348 349 /* 350 ** Release the memory held by a w_Package structs in a class loader's package 351 ** hashtable. 352 */ 353 static void trashPackages(w_word key, w_word value, void *dummy1, void*dummy2) { 354 w_package package = (w_package)value; 355 356 woempa(7, "trashing %w in %j\n", package->name, package->loader); 357 wprintf("trashing %w in %j\n", package->name, package->loader); 358 destroyPackage(package); 348 359 } 349 360 … … 368 379 if (class_hashtable->occupancy) { 369 380 ht_iterate(class_hashtable, trashUnloadedClasses, NULL, NULL); 381 } 382 releaseMem(class_hashtable->label); 383 ht_destroy(class_hashtable); 384 } 385 386 class_hashtable = getWotsitField(theClassLoader, F_ClassLoader_packages); 387 if (class_hashtable) { 388 clearWotsitField(theClassLoader, F_ClassLoader_packages); 389 woempa(7, "Releasing hashtable %s for %j\n", class_hashtable->label, theClassLoader); 390 if (class_hashtable->occupancy) { 391 ht_iterate(class_hashtable, trashPackages, NULL, NULL); 370 392 } 371 393 releaseMem(class_hashtable->label); … … 1591 1613 * - system thread group (and hence all threads) 1592 1614 * - system class hashtable (static fields of system classes) 1593 * - global references hashtable (includes current local references)1615 * - global references hashtable 1594 1616 * For every item we mark, we append all references it contains to 1595 1617 * the appropriate fifo (strong, weak, or phantom). Therefore … … 1612 1634 w_int marked = 0; 1613 1635 1614 //printf("Entering mark phase, ticks = %d\n", x_time_get() - gc_start_ticks); 1615 woempa(7, "(GC) Marking globals/locals hashtable.\n"); 1636 woempa(7, "(GC) Marking globals hashtable.\n"); 1616 1637 temp_fifo = ht_list_keys(globals_hashtable); 1617 1638 if (!temp_fifo) { Mika/trunk/core-vm/src/native/java/lang/ClassLoader.c
r495 r551 56 56 w_instance applicationClassLoader; 57 57 58 #define PACKAGE_HASHTABLE_SIZE 19 58 59 #define CLASSLOADER_HASHTABLE_SIZE 89 59 60 … … 96 97 setWotsitField(ClassLoader, F_ClassLoader_loaded_classes, system_loaded_class_hashtable); 97 98 setWotsitField(ClassLoader, F_ClassLoader_unloaded_classes, system_unloaded_class_hashtable); 98 woempa(7, "Created %j by recycling %s and %s)\n", ClassLoader, system_loaded_class_hashtable->label, system_unloaded_class_hashtable->label); 99 setWotsitField(ClassLoader, F_ClassLoader_packages, system_package_hashtable); 100 woempa(7, "Created %j by recycling %s, %s and %s)\n", ClassLoader, system_loaded_class_hashtable->label, system_unloaded_class_hashtable->label, system_package_hashtable->label); 99 101 } 100 102 else { … … 122 124 setWotsitField(ClassLoader, F_ClassLoader_unloaded_classes, class_hashtable); 123 125 woempa(7, "%j: unloaded_classes in %s\n", ClassLoader, class_hashtable->label); 126 label_buf = allocMem((w_size)(string_length(clazz->dotified) + 38)); 127 if (!label_buf) { 128 wabort(ABORT_WONKA, "Unable to allocate label_buf\n"); 129 } 130 x_snprintf(label_buf, string_length(clazz->dotified) + 37, "hashtable:%j-packages", ClassLoader); 131 class_hashtable = ht_create(label_buf, PACKAGE_HASHTABLE_SIZE, NULL, NULL, 0, 0); 132 if (!class_hashtable) { 133 wabort(ABORT_WONKA, "Unable to allocate package hashtable\n"); 134 } 135 setWotsitField(ClassLoader, F_ClassLoader_packages, class_hashtable); 136 woempa(7, "%j: packages in %s\n", ClassLoader, class_hashtable->label); 124 137 } 125 138 } Mika/trunk/core-vm/src/vm/checks.c
r361 r551 1 1 /************************************************************************** 2 * Copyright (c) 2001, 2002 by Punch Telematix. All rights reserved. * 2 * Parts copyright (c) 2001, 2002 by Punch Telematix. All rights reserved. * 3 * Parts copyright (c) 2004, 2005, 2006, 2007, 2008 by Chris Gray, /k/ * 4 * Embedded Java Solutions. All rights reserved. * 3 5 * * 4 6 * Redistribution and use in source and binary forms, with or without * … … 159 161 160 162 w_boolean isAllowedToCall(w_clazz caller, w_method method, w_clazz objClazz) { 161 162 163 if (method->spec.declaring_clazz == caller) { 163 164 woempa(1,"This Class (%K) is same as calling Class, so any method can be called.\n",method->spec.declaring_clazz); … … 226 227 */ 227 228 w_boolean sameRuntimePackage(w_clazz clazz1, w_clazz clazz2) { 229 return clazz1->package == clazz2->package; 230 /* 228 231 w_string name1; 229 232 w_string name2; … … 284 287 285 288 return WONKA_TRUE; 286 } 287 289 */ 290 } 291 Mika/trunk/core-vm/src/vm/core-classes.in
r540 r551 321 321 loaded_classes + 322 322 unloaded_classes + 323 packages + 323 324 create ()V ClassLoader_create 324 325 _defineClass (Ljava/lang/String;[BIILjava/security/ProtectionDomain;)Ljava/lang/Class; ClassLoader_defineClass Mika/trunk/core-vm/src/vm/loading.c
r538 r551 311 311 w_clazz result = NULL; 312 312 313 result = (w_clazz)ht_read_no_lock(loader2loaded_classes(initiating_loader), (w_word)name); 313 result = (w_clazz)ht_read(loader2loaded_classes(initiating_loader), (w_word)name); 314 woempa(7, "searched loaded classes of %j for %w, found %p\n", initiating_loader, name, result); 314 315 315 316 if (!result) { … … 325 326 326 327 result = registerUnloadedClazz(result); 328 woempa(1, "returning unloaded class %p\n", result); 327 329 } 328 330 … … 347 349 x_status status; 348 350 351 threadMustBeSafe(thread); 352 349 353 if (state == CLAZZ_STATE_UNLOADED) { 350 354 w_clazz loaded; … … 377 381 } 378 382 else if (state < CLAZZ_STATE_LOADED) { 379 threadMustBeSafe(thread);380 381 383 monitor = current->resolution_monitor; 382 384 … … 401 403 } 402 404 403 /* 404 static void printBootstrapClass(w_word key, w_word value) { 405 static void loaded_class_iterator(w_word key, w_word value) { 405 406 w_string name = (w_string) key; 406 wprintf(" %w\n", name); 407 } 408 */ 409 407 w_clazz clazz = (w_clazz)value; 408 if (!clazz->loader) { 409 clazz->loader = systemClassLoader; 410 } 411 } 412 413 /* 414 ** Fix system_loaded_class_hashtable so that every class which currently 415 ** has its loader set to null points to systemClassLoader instead. 416 */ 417 static void patchLoadedClasses() { 418 ht_every(system_loaded_class_hashtable, loaded_class_iterator); 419 } 420 410 421 /* 411 422 ** Set the systemClassLoader global variable. From now on the System … … 413 424 */ 414 425 void setSystemClassLoader(w_instance scl) { 415 // w_int n;416 426 x_monitor_eternal(&system_loaded_class_hashtable->monitor); 417 /*418 wprintf("Bootstrap classes:\n");419 n = ht_every(system_loaded_class_hashtable, printBootstrapClass);420 wprintf("Total of %d bootstrap classes\n\n", n);421 */422 427 if (systemClassLoader) { 423 428 woempa(9, "Ahoy there! Someone tried to install SystemClassLoader twice ...\n"); … … 427 432 systemClassLoader = scl; 428 433 newGlobalReference(scl); 429 //releaseZipFile(bootzipfile); 434 patchLoadedClasses(); 435 patchPackages(); 430 436 } 431 437 x_monitor_exit(&system_loaded_class_hashtable->monitor); … … 721 727 system_unloaded_class_hashtable = ht_create((char*)"hashtable:system-unloaded-classes", 97, clazz_hashcode, clazz_comparator, 0, 0); 722 728 woempa(7,"created system_unloaded_class_hashtable at %p\n",system_unloaded_class_hashtable); 729 730 system_package_hashtable = ht_create((char*)"hashtable:system-packages", 17, NULL, NULL, 0, 0); 731 woempa(7,"created system_package_hashtable at %p\n",system_package_hashtable); 723 732 724 733 collectCoreFixups(); … … 1083 1092 array_clazz->loader = base_clazz->loader; 1084 1093 array_clazz->bits = 32; 1094 array_clazz->package = base_clazz->package; 1085 1095 1086 1096 name_buffer[0] = '['; Mika/trunk/core-vm/src/vm/package.c
r543 r551 29 29 **************************************************************************/ 30 30 31 #include "clazz.h" 32 #include "loading.h" 31 33 #include "package.h" 34 #include "wstrings.h" 32 35 33 36 w_package createPackage(w_string name, w_instance loader) { … … 42 45 void destroyPackage(w_package p) { 43 46 deregisterString(p->name); 44 deallocMem(p);47 releaseMem(p); 45 48 } 46 49 50 /** 51 ** Get the w_Package for a class, creating it if it does not already exist. 52 */ 53 w_package getPackageForClazz(w_clazz clazz, w_instance loader) { 54 w_string class_name = clazz->dotified; 55 w_instance effective_loader = loader ? loader : systemClassLoader; 56 w_hashtable ht = loader2packages(effective_loader); 57 w_string package_name; 58 w_int i; 59 w_int j; 60 w_package p; 61 62 for (i = 0; string_char(class_name, i) == '['; ++i); 63 for (j = string_length(class_name) - 1; string_char(class_name, j) != '.'; --j); 64 package_name = j > i ? w_substring(class_name, i, j - i) : registerString(string_empty); 65 ht_lock(ht); 66 p = (w_package)ht_read_no_lock(ht, (w_word)package_name); 67 if (!p) { 68 p = createPackage(package_name, effective_loader); 69 ht_write_no_lock(ht, (w_word)package_name, (w_word)p); 70 } 71 clazz->package = p; 72 ht_unlock(ht); 73 deregisterString(package_name); 74 75 return p; 76 } 77 78 static void package_iterator(w_word key, w_word value) { 79 w_string name = (w_string) key; 80 w_package package = (w_package)value; 81 if (!package->loader) { 82 package->loader = systemClassLoader; 83 } 84 } 85 86 /* 87 ** Fix system_package_hashtable so that every package which currently 88 ** has its loader set to null points to systemClassLoader instead. 89 */ 90 void patchPackages() { 91 ht_every(system_package_hashtable, package_iterator); 92 } 93
