1022
1023 TraceTime install_time("installCode", JVMCICompiler::codeInstallTimer());
1024 bool is_immutable_PIC = HotSpotCompiledCode::isImmutablePIC(compiled_code_handle) > 0;
1025 CodeInstaller installer(is_immutable_PIC);
1026 JVMCIEnv::CodeInstallResult result = installer.install(compiler, target_handle, compiled_code_handle, cb, installed_code_handle, speculation_log_handle, CHECK_0);
1027
1028 if (PrintCodeCacheOnCompilation) {
1029 stringStream s;
1030 // Dump code cache into a buffer before locking the tty,
1031 {
1032 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1033 CodeCache::print_summary(&s, false);
1034 }
1035 ttyLocker ttyl;
1036 tty->print_raw_cr(s.as_string());
1037 }
1038
1039 if (result != JVMCIEnv::ok) {
1040 assert(cb == NULL, "should be");
1041 } else {
1042 if (!installed_code_handle.is_null()) {
1043 assert(installed_code_handle->is_a(InstalledCode::klass()), "wrong type");
1044 nmethod::invalidate_installed_code(installed_code_handle, CHECK_0);
1045 {
1046 // Ensure that all updates to the InstalledCode fields are consistent.
1047 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
1048 InstalledCode::set_address(installed_code_handle, (jlong) cb);
1049 InstalledCode::set_version(installed_code_handle, InstalledCode::version(installed_code_handle) + 1);
1050 if (cb->is_nmethod()) {
1051 InstalledCode::set_entryPoint(installed_code_handle, (jlong) cb->as_nmethod_or_null()->verified_entry_point());
1052 } else {
1053 InstalledCode::set_entryPoint(installed_code_handle, (jlong) cb->code_begin());
1054 }
1055 if (installed_code_handle->is_a(HotSpotInstalledCode::klass())) {
1056 HotSpotInstalledCode::set_size(installed_code_handle, cb->size());
1057 HotSpotInstalledCode::set_codeStart(installed_code_handle, (jlong) cb->code_begin());
1058 HotSpotInstalledCode::set_codeSize(installed_code_handle, cb->code_size());
1059 }
1060 }
1061 nmethod* nm = cb->as_nmethod_or_null();
1062 if (nm != NULL && installed_code_handle->is_scavengable()) {
1063 assert(nm->detect_scavenge_root_oops(), "nm should be scavengable if installed_code is scavengable");
1064 if (!UseG1GC) {
1065 assert(nm->on_scavenge_root_list(), "nm should be on scavengable list");
1066 }
1067 }
1068 }
1069 }
1070 return result;
1071 C2V_END
1072
1073 C2V_VMENTRY(jint, getMetadata, (JNIEnv *jniEnv, jobject, jobject target, jobject compiled_code, jobject metadata))
1074 ResourceMark rm;
1075 HandleMark hm;
1076
1077 Handle target_handle(THREAD, JNIHandles::resolve(target));
1078 Handle compiled_code_handle(THREAD, JNIHandles::resolve(compiled_code));
1079 Handle metadata_handle(THREAD, JNIHandles::resolve(metadata));
1080
1081 CodeMetadata code_metadata;
1082 CodeBlob *cb = NULL;
1083 CodeInstaller installer(true /* immutable PIC compilation */);
1084
1085 JVMCIEnv::CodeInstallResult result = installer.gather_metadata(target_handle, compiled_code_handle, code_metadata, CHECK_0);
1086 if (result != JVMCIEnv::ok) {
1087 return result;
|
1022
1023 TraceTime install_time("installCode", JVMCICompiler::codeInstallTimer());
1024 bool is_immutable_PIC = HotSpotCompiledCode::isImmutablePIC(compiled_code_handle) > 0;
1025 CodeInstaller installer(is_immutable_PIC);
1026 JVMCIEnv::CodeInstallResult result = installer.install(compiler, target_handle, compiled_code_handle, cb, installed_code_handle, speculation_log_handle, CHECK_0);
1027
1028 if (PrintCodeCacheOnCompilation) {
1029 stringStream s;
1030 // Dump code cache into a buffer before locking the tty,
1031 {
1032 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1033 CodeCache::print_summary(&s, false);
1034 }
1035 ttyLocker ttyl;
1036 tty->print_raw_cr(s.as_string());
1037 }
1038
1039 if (result != JVMCIEnv::ok) {
1040 assert(cb == NULL, "should be");
1041 } else {
1042 if (installed_code_handle.not_null()) {
1043 assert(installed_code_handle->is_a(InstalledCode::klass()), "wrong type");
1044 nmethod::invalidate_installed_code(installed_code_handle, CHECK_0);
1045 {
1046 // Ensure that all updates to the InstalledCode fields are consistent.
1047 MutexLockerEx pl(Patching_lock, Mutex::_no_safepoint_check_flag);
1048 InstalledCode::set_address(installed_code_handle, (jlong) cb);
1049 InstalledCode::set_version(installed_code_handle, InstalledCode::version(installed_code_handle) + 1);
1050 if (cb->is_nmethod()) {
1051 InstalledCode::set_entryPoint(installed_code_handle, (jlong) cb->as_nmethod_or_null()->verified_entry_point());
1052 } else {
1053 InstalledCode::set_entryPoint(installed_code_handle, (jlong) cb->code_begin());
1054 }
1055 if (installed_code_handle->is_a(HotSpotInstalledCode::klass())) {
1056 HotSpotInstalledCode::set_size(installed_code_handle, cb->size());
1057 HotSpotInstalledCode::set_codeStart(installed_code_handle, (jlong) cb->code_begin());
1058 HotSpotInstalledCode::set_codeSize(installed_code_handle, cb->code_size());
1059 }
1060 }
1061 nmethod* nm = cb->as_nmethod_or_null();
1062 }
1063 }
1064 return result;
1065 C2V_END
1066
1067 C2V_VMENTRY(jint, getMetadata, (JNIEnv *jniEnv, jobject, jobject target, jobject compiled_code, jobject metadata))
1068 ResourceMark rm;
1069 HandleMark hm;
1070
1071 Handle target_handle(THREAD, JNIHandles::resolve(target));
1072 Handle compiled_code_handle(THREAD, JNIHandles::resolve(compiled_code));
1073 Handle metadata_handle(THREAD, JNIHandles::resolve(metadata));
1074
1075 CodeMetadata code_metadata;
1076 CodeBlob *cb = NULL;
1077 CodeInstaller installer(true /* immutable PIC compilation */);
1078
1079 JVMCIEnv::CodeInstallResult result = installer.gather_metadata(target_handle, compiled_code_handle, code_metadata, CHECK_0);
1080 if (result != JVMCIEnv::ok) {
1081 return result;
|