Skip to content

Commit 6681fc7

Browse files
author
Yudi Zheng
committed
8361569: [JVMCI] Further refine JVMCI-compiled nmethod that should not collect deoptimization profile
Reviewed-by: dnsimon, gdub
1 parent 7282f68 commit 6681fc7

File tree

18 files changed

+81
-47
lines changed

18 files changed

+81
-47
lines changed

src/hotspot/share/code/nmethod.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,10 +1936,7 @@ void nmethod::inc_decompile_count() {
19361936
if (!is_compiled_by_c2() && !is_compiled_by_jvmci()) return;
19371937
// Could be gated by ProfileTraps, but do not bother...
19381938
#if INCLUDE_JVMCI
1939-
// Deoptimization count is used by the CompileBroker to reason about compilations
1940-
// it requests so do not pollute the count for deoptimizations in non-default (i.e.
1941-
// non-CompilerBroker) compilations.
1942-
if (is_jvmci_hosted()) {
1939+
if (jvmci_skip_profile_deopt()) {
19431940
return;
19441941
}
19451942
#endif
@@ -4066,7 +4063,7 @@ const char* nmethod::jvmci_name() {
40664063
return nullptr;
40674064
}
40684065

4069-
bool nmethod::is_jvmci_hosted() const {
4070-
return jvmci_nmethod_data() != nullptr && !jvmci_nmethod_data()->is_default();
4066+
bool nmethod::jvmci_skip_profile_deopt() const {
4067+
return jvmci_nmethod_data() != nullptr && !jvmci_nmethod_data()->profile_deopt();
40714068
}
40724069
#endif

src/hotspot/share/code/nmethod.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,9 +914,9 @@ class nmethod : public CodeBlob {
914914
return jvmci_data_size() == 0 ? nullptr : (JVMCINMethodData*) jvmci_data_begin();
915915
}
916916

917-
// Returns true if a JVMCI compiled method is non-default,
918-
// i.e., not triggered by CompilerBroker
919-
bool is_jvmci_hosted() const;
917+
// Returns true if the runtime should NOT collect deoptimization profile for a JVMCI
918+
// compiled method
919+
bool jvmci_skip_profile_deopt() const;
920920
#endif
921921

922922
void oops_do(OopClosure* f) { oops_do(f, false); }

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2890,11 +2890,12 @@ C2V_VMENTRY_0(jlong, translate, (JNIEnv* env, jobject, jobject obj_handle, jbool
28902890
JVMCIObject methodObject = thisEnv->get_HotSpotNmethod_method(obj);
28912891
methodHandle mh(THREAD, thisEnv->asMethod(methodObject));
28922892
jboolean isDefault = thisEnv->get_HotSpotNmethod_isDefault(obj);
2893+
jboolean profileDeopt = thisEnv->get_HotSpotNmethod_profileDeopt(obj);
28932894
jlong compileIdSnapshot = thisEnv->get_HotSpotNmethod_compileIdSnapshot(obj);
28942895
JVMCIObject name_string = thisEnv->get_InstalledCode_name(obj);
28952896
const char* cstring = name_string.is_null() ? nullptr : thisEnv->as_utf8_string(name_string);
28962897
// Create a new HotSpotNmethod instance in the peer runtime
2897-
result = PEER_JVMCIENV->new_HotSpotNmethod(mh, cstring, isDefault, compileIdSnapshot, JVMCI_CHECK_0);
2898+
result = PEER_JVMCIENV->new_HotSpotNmethod(mh, cstring, isDefault, profileDeopt, compileIdSnapshot, JVMCI_CHECK_0);
28982899
JVMCINMethodHandle nmethod_handle(THREAD);
28992900
nmethod* nm = JVMCIENV->get_nmethod(obj, nmethod_handle);
29002901
if (result.is_null()) {

src/hotspot/share/jvmci/jvmciEnv.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ JVMCIObject JVMCIEnv::new_StackTraceElement(const methodHandle& method, int bci,
12101210
}
12111211
}
12121212

1213-
JVMCIObject JVMCIEnv::new_HotSpotNmethod(const methodHandle& method, const char* name, jboolean isDefault, jlong compileId, JVMCI_TRAPS) {
1213+
JVMCIObject JVMCIEnv::new_HotSpotNmethod(const methodHandle& method, const char* name, jboolean isDefault, jboolean profileDeopt, jlong compileId, JVMCI_TRAPS) {
12141214
JavaThread* THREAD = JVMCI::compilation_tick(JavaThread::current()); // For exception macros.
12151215

12161216
JVMCIObject methodObject = get_jvmci_method(method, JVMCI_CHECK_(JVMCIObject()));
@@ -1230,11 +1230,12 @@ JVMCIObject JVMCIEnv::new_HotSpotNmethod(const methodHandle& method, const char*
12301230
jargs.push_oop(Handle(THREAD, HotSpotJVMCI::resolve(methodObject)));
12311231
jargs.push_oop(nameStr);
12321232
jargs.push_int(isDefault);
1233+
jargs.push_int(profileDeopt);
12331234
jargs.push_long(compileId);
12341235
JavaValue result(T_VOID);
12351236
JavaCalls::call_special(&result, ik,
12361237
vmSymbols::object_initializer_name(),
1237-
vmSymbols::method_string_bool_long_signature(),
1238+
vmSymbols::method_string_bool_bool_long_signature(),
12381239
&jargs, CHECK_(JVMCIObject()));
12391240
return wrap(obj_h());
12401241
} else {

src/hotspot/share/jvmci/jvmciEnv.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ class JVMCIEnv : public ResourceObj {
426426
JVMCIObjectArray new_byte_array_array(int length, JVMCI_TRAPS);
427427

428428
JVMCIObject new_StackTraceElement(const methodHandle& method, int bci, JVMCI_TRAPS);
429-
JVMCIObject new_HotSpotNmethod(const methodHandle& method, const char* name, jboolean isDefault, jlong compileId, JVMCI_TRAPS);
429+
JVMCIObject new_HotSpotNmethod(const methodHandle& method, const char* name, jboolean isDefault, jboolean profileDeopt, jlong compileId, JVMCI_TRAPS);
430430
JVMCIObject new_VMField(JVMCIObject name, JVMCIObject type, jlong offset, jlong address, JVMCIObject value, JVMCI_TRAPS);
431431
JVMCIObject new_VMFlag(JVMCIObject name, JVMCIObject type, JVMCIObject value, JVMCI_TRAPS);
432432
JVMCIObject new_VMIntrinsicMethod(JVMCIObject declaringClass, JVMCIObject name, JVMCIObject descriptor, int id, jboolean isAvailable, jboolean c1Supported, jboolean c2Supported, JVMCI_TRAPS);

src/hotspot/share/jvmci/jvmciJavaClasses.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -100,10 +100,11 @@
100100
end_class \
101101
start_class(HotSpotNmethod, jdk_vm_ci_hotspot_HotSpotNmethod) \
102102
boolean_field(HotSpotNmethod, isDefault) \
103+
boolean_field(HotSpotNmethod, profileDeopt) \
103104
long_field(HotSpotNmethod, compileIdSnapshot) \
104105
object_field(HotSpotNmethod, method, "Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl;") \
105106
int_field(HotSpotNmethod, invalidationReason) \
106-
jvmci_constructor(HotSpotNmethod, "(Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl;Ljava/lang/String;ZJ)V") \
107+
jvmci_constructor(HotSpotNmethod, "(Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl;Ljava/lang/String;ZZJ)V") \
107108
end_class \
108109
start_class(HotSpotCompiledCode, jdk_vm_ci_hotspot_HotSpotCompiledCode) \
109110
primarray_field(HotSpotCompiledCode, targetCode, "[B") \

src/hotspot/share/jvmci/jvmciRuntime.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ void JVMCINMethodData::initialize(int nmethod_mirror_index,
747747
int nmethod_entry_patch_offset,
748748
const char* nmethod_mirror_name,
749749
bool is_default,
750+
bool profile_deopt,
750751
FailedSpeculation** failed_speculations)
751752
{
752753
_failed_speculations = failed_speculations;
@@ -761,10 +762,12 @@ void JVMCINMethodData::initialize(int nmethod_mirror_index,
761762
_properties.bits._has_name = 0;
762763
}
763764
_properties.bits._is_default = is_default;
765+
_properties.bits._profile_deopt = profile_deopt;
764766
}
765767

766768
void JVMCINMethodData::copy(JVMCINMethodData* data) {
767-
initialize(data->_nmethod_mirror_index, data->_nmethod_entry_patch_offset, data->name(), data->_properties.bits._is_default, data->_failed_speculations);
769+
initialize(data->_nmethod_mirror_index, data->_nmethod_entry_patch_offset, data->name(), data->_properties.bits._is_default,
770+
data->_properties.bits._profile_deopt, data->_failed_speculations);
768771
}
769772

770773
void JVMCINMethodData::add_failed_speculation(nmethod* nm, jlong speculation) {
@@ -2086,6 +2089,7 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
20862089
char* failure_detail = nullptr;
20872090

20882091
bool install_default = JVMCIENV->get_HotSpotNmethod_isDefault(nmethod_mirror) != 0;
2092+
bool profile_deopt = JVMCIENV->get_HotSpotNmethod_profileDeopt(nmethod_mirror) != 0;
20892093
assert(JVMCIENV->isa_HotSpotNmethod(nmethod_mirror), "must be");
20902094
JVMCIObject name = JVMCIENV->get_InstalledCode_name(nmethod_mirror);
20912095
const char* nmethod_mirror_name = name.is_null() ? nullptr : JVMCIENV->as_utf8_string(name);
@@ -2154,6 +2158,7 @@ JVMCI::CodeInstallResult JVMCIRuntime::register_method(JVMCIEnv* JVMCIENV,
21542158
nmethod_entry_patch_offset,
21552159
nmethod_mirror_name,
21562160
install_default,
2161+
profile_deopt,
21572162
failed_speculations);
21582163
nm = nmethod::new_nmethod(method,
21592164
compile_id,

src/hotspot/share/jvmci/jvmciRuntime.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ class JVMCINMethodData : public ResourceObj {
5353
struct {
5454
// Is HotSpotNmethod.name non-null? If so, the value is
5555
// embedded in the end of this object.
56-
uint8_t _has_name : 1,
56+
uint8_t _has_name : 1,
5757
// HotSpotNmethod.isDefault (e.g., compilation scheduled by CompileBroker)
58-
_is_default : 1,
59-
: 6;
58+
_is_default : 1,
59+
// HotSpotNmethod.profileDeopt
60+
_profile_deopt : 1,
61+
: 5;
6062
} bits;
6163
};
6264

@@ -87,6 +89,7 @@ class JVMCINMethodData : public ResourceObj {
8789
int nmethod_entry_patch_offset,
8890
const char* nmethod_mirror_name,
8991
bool is_default,
92+
bool profile_deopt,
9093
FailedSpeculation** failed_speculations);
9194

9295
void* operator new(size_t size, const char* nmethod_mirror_name) {
@@ -100,12 +103,14 @@ class JVMCINMethodData : public ResourceObj {
100103
int nmethod_entry_patch_offset,
101104
const char* nmethod_mirror_name,
102105
bool is_default,
106+
bool profile_deopt,
103107
FailedSpeculation** failed_speculations) {
104108
JVMCINMethodData* result = new (nmethod_mirror_name) JVMCINMethodData();
105109
result->initialize(nmethod_mirror_index,
106110
nmethod_entry_patch_offset,
107111
nmethod_mirror_name,
108112
is_default,
113+
profile_deopt,
109114
failed_speculations);
110115
return result;
111116
}
@@ -153,6 +158,10 @@ class JVMCINMethodData : public ResourceObj {
153158
bool is_default() {
154159
return _properties.bits._is_default;
155160
}
161+
162+
bool profile_deopt() {
163+
return _properties.bits._profile_deopt;
164+
}
156165
};
157166

158167
// A top level class that represents an initialized JVMCI runtime.

src/hotspot/share/jvmci/vmSymbols_jvmci.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
template(bootstrapFinished_name, "bootstrapFinished") \
103103
template(forPrimitive_name, "forPrimitive") \
104104
template(forPrimitive_signature, "(CJ)Ljdk/vm/ci/meta/PrimitiveConstant;") \
105-
template(method_string_bool_long_signature, "(Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl;Ljava/lang/String;ZJ)V") \
105+
template(method_string_bool_bool_long_signature, "(Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl;Ljava/lang/String;ZZJ)V") \
106106

107107
#endif
108108

src/hotspot/share/runtime/deoptimization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2367,7 +2367,7 @@ JRT_ENTRY(void, Deoptimization::uncommon_trap_inner(JavaThread* current, jint tr
23672367
// Deoptimization count is used by the CompileBroker to reason about compilations
23682368
// it requests so do not pollute the count for deoptimizations in non-default (i.e.
23692369
// non-CompilerBroker) compilations.
2370-
if (nm->is_jvmci_hosted()) {
2370+
if (nm->jvmci_skip_profile_deopt()) {
23712371
update_trap_state = false;
23722372
}
23732373
#endif

0 commit comments

Comments
 (0)