Skip to content

Commit 61f35bf

Browse files
committed
8219403: JVMCIRuntime::adjust_comp_level should be replaced
Reviewed-by: kvn, dnsimon, never
1 parent c735803 commit 61f35bf

File tree

13 files changed

+104
-186
lines changed

13 files changed

+104
-186
lines changed

src/hotspot/share/jvmci/jvmciCompiler.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "precompiled.hpp"
2525
#include "jvm.h"
26+
#include "classfile/moduleEntry.hpp"
2627
#include "memory/oopFactory.hpp"
2728
#include "memory/resourceArea.hpp"
2829
#include "oops/oop.inline.hpp"
@@ -190,15 +191,6 @@ void JVMCICompiler::compile_method(const methodHandle& method, int entry_bci, JV
190191
}
191192
}
192193

193-
CompLevel JVMCIRuntime::adjust_comp_level(const methodHandle& method, bool is_osr, CompLevel level, JavaThread* thread) {
194-
if (!thread->adjusting_comp_level()) {
195-
thread->set_adjusting_comp_level(true);
196-
level = adjust_comp_level_inner(method, is_osr, level, thread);
197-
thread->set_adjusting_comp_level(false);
198-
}
199-
return level;
200-
}
201-
202194
void JVMCICompiler::exit_on_pending_exception(oop exception, const char* message) {
203195
JavaThread* THREAD = JavaThread::current();
204196
CLEAR_PENDING_EXCEPTION;
@@ -235,3 +227,33 @@ void JVMCICompiler::print_compilation_timers() {
235227
TRACE_jvmci_1("JVMCICompiler::print_timers");
236228
tty->print_cr(" JVMCI code install time: %6.3f s", _codeInstallTimer.seconds());
237229
}
230+
231+
bool JVMCICompiler::force_comp_at_level_simple(Method *method) {
232+
JVMCI_EXCEPTION_CONTEXT
233+
234+
if (_bootstrapping) {
235+
// When bootstrapping, the JVMCI compiler can compile its own methods.
236+
return false;
237+
}
238+
239+
if (!JVMCIRuntime::is_HotSpotJVMCIRuntime_initialized()) {
240+
// JVMCI cannot participate in compilation scheduling until
241+
// JVMCI is initialized and indicates it wants to participate.
242+
return false;
243+
}
244+
// Support for graal.CompileGraalWithC1Only
245+
HandleMark hm(thread);
246+
jobject runtime = JVMCIRuntime::get_HotSpotJVMCIRuntime_jobject(CATCH);
247+
objArrayHandle excludeFromJVMCICompilation(thread, HotSpotJVMCIRuntime::excludeFromJVMCICompilation(runtime));
248+
if (excludeFromJVMCICompilation.is_null()) {
249+
return false;
250+
}
251+
ModuleEntry *module = method->method_holder()->module();
252+
for (int i = 0; i < excludeFromJVMCICompilation->length(); ++i) {
253+
if (module->module() == excludeFromJVMCICompilation->obj_at(i)) {
254+
return true;
255+
}
256+
}
257+
258+
return false;
259+
}

src/hotspot/share/jvmci/jvmciCompiler.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class JVMCICompiler : public AbstractCompiler {
8585
*/
8686
void bootstrap(TRAPS);
8787

88+
// Should force compilation of method at CompLevel_simple?
89+
bool force_comp_at_level_simple(Method* method);
90+
8891
bool is_bootstrapping() const { return _bootstrapping; }
8992

9093
// Compilation entry point for methods

src/hotspot/share/jvmci/jvmciJavaClasses.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ class JVMCIJavaClasses : AllStatic {
312312
long_field(HotSpotConstantPool, metaspaceConstantPool) \
313313
end_class \
314314
start_class(HotSpotJVMCIRuntime) \
315-
int_field(HotSpotJVMCIRuntime, compilationLevelAdjustment) \
315+
objArrayOop_field(HotSpotJVMCIRuntime, excludeFromJVMCICompilation, "[Ljava/lang/Module;") \
316316
end_class \
317317
/* end*/
318318

src/hotspot/share/jvmci/jvmciRuntime.cpp

Lines changed: 3 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "jvm.h"
2626
#include "asm/codeBuffer.hpp"
2727
#include "classfile/javaClasses.inline.hpp"
28+
#include "classfile/moduleEntry.hpp"
2829
#include "code/codeCache.hpp"
2930
#include "code/compiledMethod.inline.hpp"
3031
#include "compiler/compileBroker.hpp"
@@ -60,9 +61,7 @@
6061
#endif
6162

6263
jobject JVMCIRuntime::_HotSpotJVMCIRuntime_instance = NULL;
63-
bool JVMCIRuntime::_HotSpotJVMCIRuntime_initialized = false;
6464
bool JVMCIRuntime::_well_known_classes_initialized = false;
65-
JVMCIRuntime::CompLevelAdjustment JVMCIRuntime::_comp_level_adjustment = JVMCIRuntime::none;
6665
bool JVMCIRuntime::_shutdown_called = false;
6766

6867
BasicType JVMCIRuntime::kindToBasicType(Handle kind, TRAPS) {
@@ -740,7 +739,7 @@ Handle JVMCIRuntime::get_HotSpotJVMCIRuntime(TRAPS) {
740739
}
741740

742741
void JVMCIRuntime::initialize_HotSpotJVMCIRuntime(TRAPS) {
743-
guarantee(!_HotSpotJVMCIRuntime_initialized, "cannot reinitialize HotSpotJVMCIRuntime");
742+
guarantee(!is_HotSpotJVMCIRuntime_initialized(), "cannot reinitialize HotSpotJVMCIRuntime");
744743
JVMCIRuntime::initialize_well_known_classes(CHECK);
745744
// This should only be called in the context of the JVMCI class being initialized
746745
InstanceKlass* klass = SystemDictionary::JVMCI_klass();
@@ -750,12 +749,6 @@ void JVMCIRuntime::initialize_HotSpotJVMCIRuntime(TRAPS) {
750749
Handle result = callStatic("jdk/vm/ci/hotspot/HotSpotJVMCIRuntime",
751750
"runtime",
752751
"()Ljdk/vm/ci/hotspot/HotSpotJVMCIRuntime;", NULL, CHECK);
753-
int adjustment = HotSpotJVMCIRuntime::compilationLevelAdjustment(result);
754-
assert(adjustment >= JVMCIRuntime::none &&
755-
adjustment <= JVMCIRuntime::by_full_signature,
756-
"compilation level adjustment out of bounds");
757-
_comp_level_adjustment = (CompLevelAdjustment) adjustment;
758-
_HotSpotJVMCIRuntime_initialized = true;
759752
_HotSpotJVMCIRuntime_instance = JNIHandles::make_global(result);
760753
}
761754

@@ -765,7 +758,7 @@ void JVMCIRuntime::initialize_JVMCI(TRAPS) {
765758
"getRuntime",
766759
"()Ljdk/vm/ci/runtime/JVMCIRuntime;", NULL, CHECK);
767760
}
768-
assert(_HotSpotJVMCIRuntime_initialized == true, "what?");
761+
assert(is_HotSpotJVMCIRuntime_initialized(), "what?");
769762
}
770763

771764
bool JVMCIRuntime::can_initialize_JVMCI() {
@@ -894,73 +887,6 @@ void JVMCIRuntime::shutdown(TRAPS) {
894887
}
895888
}
896889

897-
CompLevel JVMCIRuntime::adjust_comp_level_inner(const methodHandle& method, bool is_osr, CompLevel level, JavaThread* thread) {
898-
JVMCICompiler* compiler = JVMCICompiler::instance(false, thread);
899-
if (compiler != NULL && compiler->is_bootstrapping()) {
900-
return level;
901-
}
902-
if (!is_HotSpotJVMCIRuntime_initialized() || _comp_level_adjustment == JVMCIRuntime::none) {
903-
// JVMCI cannot participate in compilation scheduling until
904-
// JVMCI is initialized and indicates it wants to participate.
905-
return level;
906-
}
907-
908-
#define CHECK_RETURN THREAD); \
909-
if (HAS_PENDING_EXCEPTION) { \
910-
Handle exception(THREAD, PENDING_EXCEPTION); \
911-
CLEAR_PENDING_EXCEPTION; \
912-
\
913-
if (exception->is_a(SystemDictionary::ThreadDeath_klass())) { \
914-
/* In the special case of ThreadDeath, we need to reset the */ \
915-
/* pending async exception so that it is propagated. */ \
916-
thread->set_pending_async_exception(exception()); \
917-
return level; \
918-
} \
919-
tty->print("Uncaught exception while adjusting compilation level: "); \
920-
java_lang_Throwable::print(exception(), tty); \
921-
tty->cr(); \
922-
java_lang_Throwable::print_stack_trace(exception, tty); \
923-
if (HAS_PENDING_EXCEPTION) { \
924-
CLEAR_PENDING_EXCEPTION; \
925-
} \
926-
return level; \
927-
} \
928-
(void)(0
929-
930-
931-
Thread* THREAD = thread;
932-
HandleMark hm;
933-
Handle receiver = JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK_RETURN);
934-
Handle name;
935-
Handle sig;
936-
if (_comp_level_adjustment == JVMCIRuntime::by_full_signature) {
937-
name = java_lang_String::create_from_symbol(method->name(), CHECK_RETURN);
938-
sig = java_lang_String::create_from_symbol(method->signature(), CHECK_RETURN);
939-
} else {
940-
name = Handle();
941-
sig = Handle();
942-
}
943-
944-
JavaValue result(T_INT);
945-
JavaCallArguments args;
946-
args.push_oop(receiver);
947-
args.push_oop(Handle(THREAD, method->method_holder()->java_mirror()));
948-
args.push_oop(name);
949-
args.push_oop(sig);
950-
args.push_int(is_osr);
951-
args.push_int(level);
952-
JavaCalls::call_special(&result, receiver->klass(), vmSymbols::adjustCompilationLevel_name(),
953-
vmSymbols::adjustCompilationLevel_signature(), &args, CHECK_RETURN);
954-
955-
int comp_level = result.get_jint();
956-
if (comp_level < CompLevel_none || comp_level > CompLevel_full_optimization) {
957-
assert(false, "compilation level out of bounds");
958-
return level;
959-
}
960-
return (CompLevel) comp_level;
961-
#undef CHECK_RETURN
962-
}
963-
964890
void JVMCIRuntime::bootstrap_finished(TRAPS) {
965891
HandleMark hm(THREAD);
966892
Handle receiver = get_HotSpotJVMCIRuntime(CHECK);

src/hotspot/share/jvmci/jvmciRuntime.hpp

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,13 @@ class JVMCIRuntime: public AllStatic {
5353

5454
private:
5555
static jobject _HotSpotJVMCIRuntime_instance;
56-
static bool _HotSpotJVMCIRuntime_initialized;
5756
static bool _well_known_classes_initialized;
5857

59-
static CompLevelAdjustment _comp_level_adjustment;
60-
6158
static bool _shutdown_called;
6259

63-
static CompLevel adjust_comp_level_inner(const methodHandle& method, bool is_osr, CompLevel level, JavaThread* thread);
64-
6560
public:
6661
static bool is_HotSpotJVMCIRuntime_initialized() {
67-
return _HotSpotJVMCIRuntime_initialized;
62+
return _HotSpotJVMCIRuntime_instance != NULL;
6863
}
6964

7065
/**
@@ -74,7 +69,7 @@ class JVMCIRuntime: public AllStatic {
7469

7570
static jobject get_HotSpotJVMCIRuntime_jobject(TRAPS) {
7671
initialize_JVMCI(CHECK_NULL);
77-
assert(_HotSpotJVMCIRuntime_initialized, "must be");
72+
assert(_HotSpotJVMCIRuntime_instance != NULL, "must be");
7873
return _HotSpotJVMCIRuntime_instance;
7974
}
8075

@@ -107,18 +102,6 @@ class JVMCIRuntime: public AllStatic {
107102
return _shutdown_called;
108103
}
109104

110-
/**
111-
* Lets JVMCI modify the compilation level currently selected for a method by
112-
* the VM compilation policy.
113-
*
114-
* @param method the method being scheduled for compilation
115-
* @param is_osr specifies if the compilation is an OSR compilation
116-
* @param level the compilation level currently selected by the VM compilation policy
117-
* @param thread the current thread
118-
* @return the compilation level to use for the compilation
119-
*/
120-
static CompLevel adjust_comp_level(const methodHandle& method, bool is_osr, CompLevel level, JavaThread* thread);
121-
122105
static BasicType kindToBasicType(Handle kind, TRAPS);
123106

124107
static void new_instance_common(JavaThread* thread, Klass* klass, bool null_on_fail);

src/hotspot/share/jvmci/vmSymbols_jvmci.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@
9494
template(jdk_vm_ci_common_JVMCIError, "jdk/vm/ci/common/JVMCIError") \
9595
template(visitFrame_name, "visitFrame") \
9696
template(visitFrame_signature, "(Ljdk/vm/ci/code/stack/InspectedFrame;)Ljava/lang/Object;") \
97-
template(adjustCompilationLevel_name, "adjustCompilationLevel") \
98-
template(adjustCompilationLevel_signature, "(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;ZI)I") \
9997
template(compileMethod_name, "compileMethod") \
10098
template(compileMethod_signature, "(Ljdk/vm/ci/hotspot/HotSpotResolvedJavaMethod;IJI)Ljdk/vm/ci/hotspot/HotSpotCompilationRequestResult;") \
10199
template(fromMetaspace_name, "fromMetaspace") \

src/hotspot/share/runtime/thread.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1628,7 +1628,6 @@ void JavaThread::initialize() {
16281628
_pending_deoptimization = -1;
16291629
_pending_failed_speculation = 0;
16301630
_pending_transfer_to_interpreter = false;
1631-
_adjusting_comp_level = false;
16321631
_in_retryable_allocation = false;
16331632
_jvmci._alternate_call_target = NULL;
16341633
assert(_jvmci._implicit_exception_pc == NULL, "must be");

src/hotspot/share/runtime/thread.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,9 +1126,6 @@ class JavaThread: public Thread {
11261126
// Specifies if the DeoptReason for the last uncommon trap was Reason_transfer_to_interpreter
11271127
bool _pending_transfer_to_interpreter;
11281128

1129-
// Guard for re-entrant call to JVMCIRuntime::adjust_comp_level
1130-
bool _adjusting_comp_level;
1131-
11321129
// True if in a runtime call from compiled code that will deoptimize
11331130
// and re-execute a failed heap allocation in the interpreter.
11341131
bool _in_retryable_allocation;
@@ -1536,8 +1533,6 @@ class JavaThread: public Thread {
15361533
#if INCLUDE_JVMCI
15371534
int pending_deoptimization() const { return _pending_deoptimization; }
15381535
long pending_failed_speculation() const { return _pending_failed_speculation; }
1539-
bool adjusting_comp_level() const { return _adjusting_comp_level; }
1540-
void set_adjusting_comp_level(bool b) { _adjusting_comp_level = b; }
15411536
bool has_pending_monitorenter() const { return _pending_monitorenter; }
15421537
void set_pending_monitorenter(bool b) { _pending_monitorenter = b; }
15431538
void set_pending_deoptimization(int reason) { _pending_deoptimization = reason; }

src/hotspot/share/runtime/tieredThresholdPolicy.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ bool TieredThresholdPolicy::is_trivial(Method* method) {
9191
return false;
9292
}
9393

94+
bool TieredThresholdPolicy::should_compile_at_level_simple(Method* method) {
95+
if (TieredThresholdPolicy::is_trivial(method)) {
96+
return true;
97+
}
98+
#if INCLUDE_JVMCI
99+
if (UseJVMCICompiler) {
100+
AbstractCompiler* comp = CompileBroker::compiler(CompLevel_full_optimization);
101+
if (comp != NULL && comp->is_jvmci() && ((JVMCICompiler*) comp)->force_comp_at_level_simple(method)) {
102+
return true;
103+
}
104+
}
105+
#endif
106+
return false;
107+
}
108+
94109
CompLevel TieredThresholdPolicy::comp_level(Method* method) {
95110
CompiledMethod *nm = method->code();
96111
if (nm != NULL && nm->is_in_use()) {
@@ -613,7 +628,7 @@ bool TieredThresholdPolicy::call_predicate(int i, int b, CompLevel cur_level, Me
613628

614629
// Determine is a method is mature.
615630
bool TieredThresholdPolicy::is_mature(Method* method) {
616-
if (is_trivial(method)) return true;
631+
if (should_compile_at_level_simple(method)) return true;
617632
MethodData* mdo = method->method_data();
618633
if (mdo != NULL) {
619634
int i = mdo->invocation_count();
@@ -709,7 +724,7 @@ CompLevel TieredThresholdPolicy::common(Predicate p, Method* method, CompLevel c
709724
int i = method->invocation_count();
710725
int b = method->backedge_count();
711726

712-
if (is_trivial(method)) {
727+
if (should_compile_at_level_simple(method)) {
713728
next_level = CompLevel_simple;
714729
} else {
715730
switch(cur_level) {
@@ -825,11 +840,6 @@ CompLevel TieredThresholdPolicy::call_event(Method* method, CompLevel cur_level,
825840
} else {
826841
next_level = MAX2(osr_level, next_level);
827842
}
828-
#if INCLUDE_JVMCI
829-
if (UseJVMCICompiler) {
830-
next_level = JVMCIRuntime::adjust_comp_level(method, false, next_level, thread);
831-
}
832-
#endif
833843
return next_level;
834844
}
835845

@@ -844,11 +854,6 @@ CompLevel TieredThresholdPolicy::loop_event(Method* method, CompLevel cur_level,
844854
return osr_level;
845855
}
846856
}
847-
#if INCLUDE_JVMCI
848-
if (UseJVMCICompiler) {
849-
next_level = JVMCIRuntime::adjust_comp_level(method, true, next_level, thread);
850-
}
851-
#endif
852857
return next_level;
853858
}
854859

src/hotspot/share/runtime/tieredThresholdPolicy.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ class TieredThresholdPolicy : public CompilationPolicy {
231231
virtual void submit_compile(const methodHandle& mh, int bci, CompLevel level, JavaThread* thread);
232232
// Simple methods are as good being compiled with C1 as C2.
233233
// This function tells if it's such a function.
234-
inline bool is_trivial(Method* method);
234+
inline static bool is_trivial(Method* method);
235+
// Force method to be compiled at CompLevel_simple?
236+
inline static bool should_compile_at_level_simple(Method* method);
235237

236238
// Predicate helpers are used by .*_predicate() methods as well as others.
237239
// They check the given counter values, multiplied by the scale against the thresholds.

0 commit comments

Comments
 (0)