< prev index next >

src/share/vm/prims/whitebox.cpp

Print this page
rev 12479 : 8171855: Move package name transformations during module bootstrap into native code
Reviewed-by: alanb, acorn, lfoltan, mchung


  23  */
  24 
  25 #include "precompiled.hpp"
  26 
  27 #include <new>
  28 
  29 #include "classfile/classLoaderData.hpp"
  30 #include "classfile/modules.hpp"
  31 #include "classfile/stringTable.hpp"
  32 #include "code/codeCache.hpp"
  33 #include "compiler/methodMatcher.hpp"
  34 #include "compiler/directivesParser.hpp"
  35 #include "jvmtifiles/jvmtiEnv.hpp"
  36 #include "memory/metadataFactory.hpp"
  37 #include "memory/metaspaceShared.hpp"
  38 #include "memory/iterator.hpp"
  39 #include "memory/resourceArea.hpp"
  40 #include "memory/universe.hpp"
  41 #include "memory/oopFactory.hpp"
  42 #include "oops/constantPool.hpp"


  43 #include "oops/oop.inline.hpp"
  44 #include "prims/wbtestmethods/parserTests.hpp"
  45 #include "prims/whitebox.hpp"
  46 #include "runtime/arguments.hpp"
  47 #include "runtime/compilationPolicy.hpp"
  48 #include "runtime/deoptimization.hpp"
  49 #include "runtime/interfaceSupport.hpp"
  50 #include "runtime/javaCalls.hpp"
  51 #include "runtime/os.hpp"
  52 #include "runtime/sweeper.hpp"
  53 #include "runtime/thread.hpp"
  54 #include "runtime/vm_version.hpp"
  55 #include "utilities/array.hpp"
  56 #include "utilities/debug.hpp"
  57 #include "utilities/exceptions.hpp"
  58 #include "utilities/macros.hpp"
  59 #if INCLUDE_ALL_GCS
  60 #include "gc/g1/concurrentMarkThread.hpp"
  61 #include "gc/g1/g1CollectedHeap.inline.hpp"
  62 #include "gc/g1/g1ConcurrentMark.hpp"


1383   ClassLoaderData* cld = class_loader_oop != NULL
1384       ? java_lang_ClassLoader::loader_data(class_loader_oop)
1385       : ClassLoaderData::the_null_class_loader_data();
1386 
1387   void* metadata = MetadataFactory::new_writeable_array<u1>(cld, WhiteBox::array_bytes_to_length((size_t)size), thread);
1388 
1389   return (jlong)(uintptr_t)metadata;
1390 WB_END
1391 
1392 WB_ENTRY(void, WB_FreeMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong addr, jlong size))
1393   oop class_loader_oop = JNIHandles::resolve(class_loader);
1394   ClassLoaderData* cld = class_loader_oop != NULL
1395       ? java_lang_ClassLoader::loader_data(class_loader_oop)
1396       : ClassLoaderData::the_null_class_loader_data();
1397 
1398   MetadataFactory::free_array(cld, (Array<u1>*)(uintptr_t)addr);
1399 WB_END
1400 
1401 WB_ENTRY(void, WB_DefineModule(JNIEnv* env, jobject o, jobject module, jstring version, jstring location,
1402                                 jobjectArray packages))
1403   Modules::define_module(module, version, location, packages, CHECK);


















1404 WB_END
1405 
1406 WB_ENTRY(void, WB_AddModuleExports(JNIEnv* env, jobject o, jobject from_module, jstring package, jobject to_module))
1407   Modules::add_module_exports_qualified(from_module, package, to_module, CHECK);





1408 WB_END
1409 
1410 WB_ENTRY(void, WB_AddModuleExportsToAllUnnamed(JNIEnv* env, jobject o, jclass module, jstring package))
1411   Modules::add_module_exports_to_all_unnamed(module, package, CHECK);





1412 WB_END
1413 
1414 WB_ENTRY(void, WB_AddModuleExportsToAll(JNIEnv* env, jobject o, jclass module, jstring package))
1415   Modules::add_module_exports(module, package, NULL, CHECK);





1416 WB_END
1417 
1418 WB_ENTRY(void, WB_AddReadsModule(JNIEnv* env, jobject o, jobject from_module, jobject source_module))
1419   Modules::add_reads_module(from_module, source_module, CHECK);
1420 WB_END
1421 
1422 WB_ENTRY(void, WB_AddModulePackage(JNIEnv* env, jobject o, jclass module, jstring package))
1423   Modules::add_module_package(module, package, CHECK);





1424 WB_END
1425 
1426 WB_ENTRY(jobject, WB_GetModuleByPackageName(JNIEnv* env, jobject o, jobject loader, jstring package))
1427   return Modules::get_module_by_package_name(loader, package, THREAD);





1428 WB_END
1429 
1430 WB_ENTRY(jlong, WB_IncMetaspaceCapacityUntilGC(JNIEnv* env, jobject wb, jlong inc))
1431   if (inc < 0) {
1432     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1433         err_msg("WB_IncMetaspaceCapacityUntilGC: inc is negative: " JLONG_FORMAT, inc));
1434   }
1435 
1436   jlong max_size_t = (jlong) ((size_t) -1);
1437   if (inc > max_size_t) {
1438     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1439         err_msg("WB_IncMetaspaceCapacityUntilGC: inc does not fit in size_t: " JLONG_FORMAT, inc));
1440   }
1441 
1442   size_t new_cap_until_GC = 0;
1443   size_t aligned_inc = align_size_down((size_t) inc, Metaspace::commit_alignment());
1444   bool success = MetaspaceGC::inc_capacity_until_GC(aligned_inc, &new_cap_until_GC);
1445   if (!success) {
1446     THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(),
1447                 "WB_IncMetaspaceCapacityUntilGC: could not increase capacity until GC "




  23  */
  24 
  25 #include "precompiled.hpp"
  26 
  27 #include <new>
  28 
  29 #include "classfile/classLoaderData.hpp"
  30 #include "classfile/modules.hpp"
  31 #include "classfile/stringTable.hpp"
  32 #include "code/codeCache.hpp"
  33 #include "compiler/methodMatcher.hpp"
  34 #include "compiler/directivesParser.hpp"
  35 #include "jvmtifiles/jvmtiEnv.hpp"
  36 #include "memory/metadataFactory.hpp"
  37 #include "memory/metaspaceShared.hpp"
  38 #include "memory/iterator.hpp"
  39 #include "memory/resourceArea.hpp"
  40 #include "memory/universe.hpp"
  41 #include "memory/oopFactory.hpp"
  42 #include "oops/constantPool.hpp"
  43 #include "oops/objArrayKlass.hpp"
  44 #include "oops/objArrayOop.inline.hpp"
  45 #include "oops/oop.inline.hpp"
  46 #include "prims/wbtestmethods/parserTests.hpp"
  47 #include "prims/whitebox.hpp"
  48 #include "runtime/arguments.hpp"
  49 #include "runtime/compilationPolicy.hpp"
  50 #include "runtime/deoptimization.hpp"
  51 #include "runtime/interfaceSupport.hpp"
  52 #include "runtime/javaCalls.hpp"
  53 #include "runtime/os.hpp"
  54 #include "runtime/sweeper.hpp"
  55 #include "runtime/thread.hpp"
  56 #include "runtime/vm_version.hpp"
  57 #include "utilities/array.hpp"
  58 #include "utilities/debug.hpp"
  59 #include "utilities/exceptions.hpp"
  60 #include "utilities/macros.hpp"
  61 #if INCLUDE_ALL_GCS
  62 #include "gc/g1/concurrentMarkThread.hpp"
  63 #include "gc/g1/g1CollectedHeap.inline.hpp"
  64 #include "gc/g1/g1ConcurrentMark.hpp"


1385   ClassLoaderData* cld = class_loader_oop != NULL
1386       ? java_lang_ClassLoader::loader_data(class_loader_oop)
1387       : ClassLoaderData::the_null_class_loader_data();
1388 
1389   void* metadata = MetadataFactory::new_writeable_array<u1>(cld, WhiteBox::array_bytes_to_length((size_t)size), thread);
1390 
1391   return (jlong)(uintptr_t)metadata;
1392 WB_END
1393 
1394 WB_ENTRY(void, WB_FreeMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong addr, jlong size))
1395   oop class_loader_oop = JNIHandles::resolve(class_loader);
1396   ClassLoaderData* cld = class_loader_oop != NULL
1397       ? java_lang_ClassLoader::loader_data(class_loader_oop)
1398       : ClassLoaderData::the_null_class_loader_data();
1399 
1400   MetadataFactory::free_array(cld, (Array<u1>*)(uintptr_t)addr);
1401 WB_END
1402 
1403 WB_ENTRY(void, WB_DefineModule(JNIEnv* env, jobject o, jobject module, jstring version, jstring location,
1404                                 jobjectArray packages))
1405   ResourceMark rm(THREAD);
1406 
1407   objArrayOop packages_oop = objArrayOop(JNIHandles::resolve(packages));
1408   objArrayHandle packages_h(THREAD, packages_oop);
1409   int num_packages = (packages_h == NULL ? 0 : packages_h->length());
1410 
1411   char** pkgs = NULL;
1412   if (num_packages > 0) {
1413     pkgs = new char*[num_packages];
1414     for (int x = 0; x < num_packages; x++) {
1415       oop pkg_str = packages_h->obj_at(x);
1416       if (pkg_str == NULL || !pkg_str->is_a(SystemDictionary::String_klass())) {
1417         THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1418                   err_msg("Bad package name"));
1419       }
1420       pkgs[x] = java_lang_String::as_utf8_string(pkg_str);
1421     }
1422   }
1423   Modules::define_module(module, version, location, (const char* const*)pkgs, num_packages, CHECK);
1424 WB_END
1425 
1426 WB_ENTRY(void, WB_AddModuleExports(JNIEnv* env, jobject o, jobject from_module, jstring package, jobject to_module))
1427   ResourceMark rm(THREAD);
1428   char* package_name = NULL;
1429   if (package != NULL) {
1430       package_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(package));
1431   }
1432   Modules::add_module_exports_qualified(from_module, package_name, to_module, CHECK);
1433 WB_END
1434 
1435 WB_ENTRY(void, WB_AddModuleExportsToAllUnnamed(JNIEnv* env, jobject o, jclass module, jstring package))
1436   ResourceMark rm(THREAD);
1437   char* package_name = NULL;
1438   if (package != NULL) {
1439       package_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(package));
1440   }
1441   Modules::add_module_exports_to_all_unnamed(module, package_name, CHECK);
1442 WB_END
1443 
1444 WB_ENTRY(void, WB_AddModuleExportsToAll(JNIEnv* env, jobject o, jclass module, jstring package))
1445   ResourceMark rm(THREAD);
1446   char* package_name = NULL;
1447   if (package != NULL) {
1448       package_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(package));
1449   }
1450   Modules::add_module_exports(module, package_name, NULL, CHECK);
1451 WB_END
1452 
1453 WB_ENTRY(void, WB_AddReadsModule(JNIEnv* env, jobject o, jobject from_module, jobject source_module))
1454   Modules::add_reads_module(from_module, source_module, CHECK);
1455 WB_END
1456 
1457 WB_ENTRY(void, WB_AddModulePackage(JNIEnv* env, jobject o, jclass module, jstring package))
1458   ResourceMark rm(THREAD);
1459   char* package_name = NULL;
1460   if (package != NULL) {
1461       package_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(package));
1462   }
1463   Modules::add_module_package(module, package_name, CHECK);
1464 WB_END
1465 
1466 WB_ENTRY(jobject, WB_GetModuleByPackageName(JNIEnv* env, jobject o, jobject loader, jstring package))
1467   ResourceMark rm(THREAD);
1468   char* package_name = NULL;
1469   if (package != NULL) {
1470       package_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(package));
1471   }
1472   return Modules::get_module_by_package_name(loader, package_name, THREAD);
1473 WB_END
1474 
1475 WB_ENTRY(jlong, WB_IncMetaspaceCapacityUntilGC(JNIEnv* env, jobject wb, jlong inc))
1476   if (inc < 0) {
1477     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1478         err_msg("WB_IncMetaspaceCapacityUntilGC: inc is negative: " JLONG_FORMAT, inc));
1479   }
1480 
1481   jlong max_size_t = (jlong) ((size_t) -1);
1482   if (inc > max_size_t) {
1483     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1484         err_msg("WB_IncMetaspaceCapacityUntilGC: inc does not fit in size_t: " JLONG_FORMAT, inc));
1485   }
1486 
1487   size_t new_cap_until_GC = 0;
1488   size_t aligned_inc = align_size_down((size_t) inc, Metaspace::commit_alignment());
1489   bool success = MetaspaceGC::inc_capacity_until_GC(aligned_inc, &new_cap_until_GC);
1490   if (!success) {
1491     THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(),
1492                 "WB_IncMetaspaceCapacityUntilGC: could not increase capacity until GC "


< prev index next >