88 loaders[i] = null; 89 } 90 91 System.gc(); 92 93 report("After releasing second half of class loaders: "); 94 95 // The garbage collector in Tiger actually has reclaimed all class 96 // loaders at this point, but in order not to become too dependent 97 // on the current behavior, we only require that the first half 98 // has been reclaimed. 99 if (countLoaders(0, CLASS_LOADER_COUNT / 2) > 0) { 100 throw new RuntimeException("Too many class loaders not reclaimed yet."); 101 } 102 } 103 104 private static void report(String when) throws Exception { 105 int first = countLoaders(0, CLASS_LOADER_COUNT / 2); 106 int second = countLoaders(CLASS_LOADER_COUNT / 2, CLASS_LOADER_COUNT); 107 108 Class clazz = ResourceBundle.class; 109 Field cacheList = clazz.getDeclaredField("cacheList"); 110 cacheList.setAccessible(true); 111 int cacheSize = ((Map)cacheList.get(clazz)).size(); 112 113 System.out.println(when); 114 System.out.println(" " + first + " loaders alive in first half"); 115 System.out.println(" " + second + " loaders alive in second half"); 116 System.out.println(" " + cacheSize + " entries in resource bundle cache"); 117 } 118 119 private static void loadBundles(int start, int end) throws Exception { 120 for (int i = start; i < end; i++) { 121 // There's no resource bundle for NonExistantBundle - this 122 // let's us test the case where a resource bundle is not found, 123 // which in the past created a SoftReference on the value side 124 // of the cache. 125 try { 126 ResourceBundle.getBundle("NonExistantBundle", Locale.US, loaders[i]); 127 } catch (MissingResourceException e) { 128 } 129 // There's a base resource bundle for ReferencesTestBundle - the 130 // normal case. 131 ResourceBundle.getBundle("ReferencesTestBundle", Locale.US, loaders[i]); 132 } 133 } 134 135 private static int countLoaders(int start, int end) { 136 int count = 0; | 88 loaders[i] = null; 89 } 90 91 System.gc(); 92 93 report("After releasing second half of class loaders: "); 94 95 // The garbage collector in Tiger actually has reclaimed all class 96 // loaders at this point, but in order not to become too dependent 97 // on the current behavior, we only require that the first half 98 // has been reclaimed. 99 if (countLoaders(0, CLASS_LOADER_COUNT / 2) > 0) { 100 throw new RuntimeException("Too many class loaders not reclaimed yet."); 101 } 102 } 103 104 private static void report(String when) throws Exception { 105 int first = countLoaders(0, CLASS_LOADER_COUNT / 2); 106 int second = countLoaders(CLASS_LOADER_COUNT / 2, CLASS_LOADER_COUNT); 107 108 System.out.println(when); 109 System.out.println(" " + first + " loaders alive in first half"); 110 System.out.println(" " + second + " loaders alive in second half"); 111 } 112 113 private static void loadBundles(int start, int end) throws Exception { 114 for (int i = start; i < end; i++) { 115 // There's no resource bundle for NonExistantBundle - this 116 // let's us test the case where a resource bundle is not found, 117 // which in the past created a SoftReference on the value side 118 // of the cache. 119 try { 120 ResourceBundle.getBundle("NonExistantBundle", Locale.US, loaders[i]); 121 } catch (MissingResourceException e) { 122 } 123 // There's a base resource bundle for ReferencesTestBundle - the 124 // normal case. 125 ResourceBundle.getBundle("ReferencesTestBundle", Locale.US, loaders[i]); 126 } 127 } 128 129 private static int countLoaders(int start, int end) { 130 int count = 0; |