137 138 WB_ENTRY(void, WB_AddToSystemClassLoaderSearch(JNIEnv* env, jobject o, jstring segment)) { 139 #if INCLUDE_JVMTI 140 ResourceMark rm; 141 const char* seg = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(segment)); 142 JvmtiEnv* jvmti_env = JvmtiEnv::create_a_jvmti(JVMTI_VERSION); 143 jvmtiError err = jvmti_env->AddToSystemClassLoaderSearch(seg); 144 assert(err == JVMTI_ERROR_NONE, "must not fail"); 145 #endif 146 } 147 WB_END 148 149 150 WB_ENTRY(jlong, WB_GetCompressedOopsMaxHeapSize(JNIEnv* env, jobject o)) { 151 return (jlong)Arguments::max_heap_for_compressed_oops(); 152 } 153 WB_END 154 155 WB_ENTRY(void, WB_PrintHeapSizes(JNIEnv* env, jobject o)) { 156 CollectorPolicy * p = Universe::heap()->collector_policy(); 157 gclog_or_tty->print_cr("Minimum heap "SIZE_FORMAT" Initial heap " 158 SIZE_FORMAT" Maximum heap "SIZE_FORMAT" Space alignment "SIZE_FORMAT" Heap alignment "SIZE_FORMAT, 159 p->min_heap_byte_size(), p->initial_heap_byte_size(), p->max_heap_byte_size(), 160 p->space_alignment(), p->heap_alignment()); 161 } 162 WB_END 163 164 #ifndef PRODUCT 165 // Forward declaration 166 void TestReservedSpace_test(); 167 void TestReserveMemorySpecial_test(); 168 void TestVirtualSpace_test(); 169 void TestMetaspaceAux_test(); 170 #endif 171 172 WB_ENTRY(void, WB_RunMemoryUnitTests(JNIEnv* env, jobject o)) 173 #ifndef PRODUCT 174 TestReservedSpace_test(); 175 TestReserveMemorySpecial_test(); 176 TestVirtualSpace_test(); 177 TestMetaspaceAux_test(); 178 #endif 179 WB_END 180 181 WB_ENTRY(void, WB_ReadFromNoaccessArea(JNIEnv* env, jobject o)) 182 size_t granularity = os::vm_allocation_granularity(); 183 ReservedHeapSpace rhs(100 * granularity, granularity, false); 184 VirtualSpace vs; 185 vs.initialize(rhs, 50 * granularity); 186 187 // Check if constraints are complied 188 if (!( UseCompressedOops && rhs.base() != NULL && 189 Universe::narrow_oop_base() != NULL && 190 Universe::narrow_oop_use_implicit_null_checks() )) { 191 tty->print_cr("WB_ReadFromNoaccessArea method is useless:\n " 192 "\tUseCompressedOops is %d\n" 193 "\trhs.base() is "PTR_FORMAT"\n" 194 "\tUniverse::narrow_oop_base() is "PTR_FORMAT"\n" 195 "\tUniverse::narrow_oop_use_implicit_null_checks() is %d", 196 UseCompressedOops, 197 rhs.base(), 198 Universe::narrow_oop_base(), 199 Universe::narrow_oop_use_implicit_null_checks()); 200 return; 201 } 202 tty->print_cr("Reading from no access area... "); 203 tty->print_cr("*(vs.low_boundary() - rhs.noaccess_prefix() / 2 ) = %c", 204 *(vs.low_boundary() - rhs.noaccess_prefix() / 2 )); 205 WB_END 206 207 static jint wb_stress_virtual_space_resize(size_t reserved_space_size, 208 size_t magnitude, size_t iterations) { 209 size_t granularity = os::vm_allocation_granularity(); 210 ReservedHeapSpace rhs(reserved_space_size * granularity, granularity, false); 211 VirtualSpace vs; 212 if (!vs.initialize(rhs, 0)) { 213 tty->print_cr("Failed to initialize VirtualSpace. Can't proceed."); 214 return 3; 227 size_t delta = (size_t)os::random() % magnitude; 228 229 // If we are about to shrink virtual space below zero, then expand instead 230 if (shrink && vs.committed_size() < delta) { 231 shrink = false; 232 } 233 234 // Resizing by delta 235 if (shrink) { 236 vs.shrink_by(delta); 237 } else { 238 // If expanding fails expand_by will silently return false 239 vs.expand_by(delta, true); 240 } 241 } 242 return 0; 243 } 244 245 WB_ENTRY(jint, WB_StressVirtualSpaceResize(JNIEnv* env, jobject o, 246 jlong reserved_space_size, jlong magnitude, jlong iterations)) 247 tty->print_cr("reservedSpaceSize="JLONG_FORMAT", magnitude="JLONG_FORMAT", " 248 "iterations="JLONG_FORMAT"\n", reserved_space_size, magnitude, 249 iterations); 250 if (reserved_space_size < 0 || magnitude < 0 || iterations < 0) { 251 tty->print_cr("One of variables printed above is negative. Can't proceed.\n"); 252 return 1; 253 } 254 255 // sizeof(size_t) depends on whether OS is 32bit or 64bit. sizeof(jlong) is 256 // always 8 byte. That's why we should avoid overflow in case of 32bit platform. 257 if (sizeof(size_t) < sizeof(jlong)) { 258 jlong size_t_max_value = (jlong) SIZE_T_MAX_VALUE; 259 if (reserved_space_size > size_t_max_value || magnitude > size_t_max_value 260 || iterations > size_t_max_value) { 261 tty->print_cr("One of variables printed above overflows size_t. Can't proceed.\n"); 262 return 2; 263 } 264 } 265 266 return wb_stress_virtual_space_resize((size_t) reserved_space_size, 267 (size_t) magnitude, (size_t) iterations); 268 WB_END | 137 138 WB_ENTRY(void, WB_AddToSystemClassLoaderSearch(JNIEnv* env, jobject o, jstring segment)) { 139 #if INCLUDE_JVMTI 140 ResourceMark rm; 141 const char* seg = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(segment)); 142 JvmtiEnv* jvmti_env = JvmtiEnv::create_a_jvmti(JVMTI_VERSION); 143 jvmtiError err = jvmti_env->AddToSystemClassLoaderSearch(seg); 144 assert(err == JVMTI_ERROR_NONE, "must not fail"); 145 #endif 146 } 147 WB_END 148 149 150 WB_ENTRY(jlong, WB_GetCompressedOopsMaxHeapSize(JNIEnv* env, jobject o)) { 151 return (jlong)Arguments::max_heap_for_compressed_oops(); 152 } 153 WB_END 154 155 WB_ENTRY(void, WB_PrintHeapSizes(JNIEnv* env, jobject o)) { 156 CollectorPolicy * p = Universe::heap()->collector_policy(); 157 gclog_or_tty->print_cr("Minimum heap " SIZE_FORMAT " Initial heap " 158 SIZE_FORMAT " Maximum heap " SIZE_FORMAT " Space alignment " SIZE_FORMAT " Heap alignment " SIZE_FORMAT, 159 p->min_heap_byte_size(), p->initial_heap_byte_size(), p->max_heap_byte_size(), 160 p->space_alignment(), p->heap_alignment()); 161 } 162 WB_END 163 164 #ifndef PRODUCT 165 // Forward declaration 166 void TestReservedSpace_test(); 167 void TestReserveMemorySpecial_test(); 168 void TestVirtualSpace_test(); 169 void TestMetaspaceAux_test(); 170 #endif 171 172 WB_ENTRY(void, WB_RunMemoryUnitTests(JNIEnv* env, jobject o)) 173 #ifndef PRODUCT 174 TestReservedSpace_test(); 175 TestReserveMemorySpecial_test(); 176 TestVirtualSpace_test(); 177 TestMetaspaceAux_test(); 178 #endif 179 WB_END 180 181 WB_ENTRY(void, WB_ReadFromNoaccessArea(JNIEnv* env, jobject o)) 182 size_t granularity = os::vm_allocation_granularity(); 183 ReservedHeapSpace rhs(100 * granularity, granularity, false); 184 VirtualSpace vs; 185 vs.initialize(rhs, 50 * granularity); 186 187 // Check if constraints are complied 188 if (!( UseCompressedOops && rhs.base() != NULL && 189 Universe::narrow_oop_base() != NULL && 190 Universe::narrow_oop_use_implicit_null_checks() )) { 191 tty->print_cr("WB_ReadFromNoaccessArea method is useless:\n " 192 "\tUseCompressedOops is %d\n" 193 "\trhs.base() is " PTR_FORMAT "\n" 194 "\tUniverse::narrow_oop_base() is " PTR_FORMAT "\n" 195 "\tUniverse::narrow_oop_use_implicit_null_checks() is %d", 196 UseCompressedOops, 197 rhs.base(), 198 Universe::narrow_oop_base(), 199 Universe::narrow_oop_use_implicit_null_checks()); 200 return; 201 } 202 tty->print_cr("Reading from no access area... "); 203 tty->print_cr("*(vs.low_boundary() - rhs.noaccess_prefix() / 2 ) = %c", 204 *(vs.low_boundary() - rhs.noaccess_prefix() / 2 )); 205 WB_END 206 207 static jint wb_stress_virtual_space_resize(size_t reserved_space_size, 208 size_t magnitude, size_t iterations) { 209 size_t granularity = os::vm_allocation_granularity(); 210 ReservedHeapSpace rhs(reserved_space_size * granularity, granularity, false); 211 VirtualSpace vs; 212 if (!vs.initialize(rhs, 0)) { 213 tty->print_cr("Failed to initialize VirtualSpace. Can't proceed."); 214 return 3; 227 size_t delta = (size_t)os::random() % magnitude; 228 229 // If we are about to shrink virtual space below zero, then expand instead 230 if (shrink && vs.committed_size() < delta) { 231 shrink = false; 232 } 233 234 // Resizing by delta 235 if (shrink) { 236 vs.shrink_by(delta); 237 } else { 238 // If expanding fails expand_by will silently return false 239 vs.expand_by(delta, true); 240 } 241 } 242 return 0; 243 } 244 245 WB_ENTRY(jint, WB_StressVirtualSpaceResize(JNIEnv* env, jobject o, 246 jlong reserved_space_size, jlong magnitude, jlong iterations)) 247 tty->print_cr("reservedSpaceSize=" JLONG_FORMAT ", magnitude=" JLONG_FORMAT ", " 248 "iterations=" JLONG_FORMAT "\n", reserved_space_size, magnitude, 249 iterations); 250 if (reserved_space_size < 0 || magnitude < 0 || iterations < 0) { 251 tty->print_cr("One of variables printed above is negative. Can't proceed.\n"); 252 return 1; 253 } 254 255 // sizeof(size_t) depends on whether OS is 32bit or 64bit. sizeof(jlong) is 256 // always 8 byte. That's why we should avoid overflow in case of 32bit platform. 257 if (sizeof(size_t) < sizeof(jlong)) { 258 jlong size_t_max_value = (jlong) SIZE_T_MAX_VALUE; 259 if (reserved_space_size > size_t_max_value || magnitude > size_t_max_value 260 || iterations > size_t_max_value) { 261 tty->print_cr("One of variables printed above overflows size_t. Can't proceed.\n"); 262 return 2; 263 } 264 } 265 266 return wb_stress_virtual_space_resize((size_t) reserved_space_size, 267 (size_t) magnitude, (size_t) iterations); 268 WB_END |