author | erikj |
Fri, 05 Oct 2018 09:59:30 -0700 | |
branch | ihse-runtestprebuilt-branch |
changeset 56931 | aff106ae3507 |
parent 50858 | 2d3e99a72541 |
child 52934 | 8deeb7bba516 |
permissions | -rw-r--r-- |
33160 | 1 |
/* |
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
47765
diff
changeset
|
2 |
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. |
33160 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
#include "precompiled.hpp" |
|
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47216
diff
changeset
|
25 |
#include "jvm.h" |
33160 | 26 |
#include "memory/oopFactory.hpp" |
37248 | 27 |
#include "memory/resourceArea.hpp" |
33160 | 28 |
#include "oops/oop.inline.hpp" |
29 |
#include "runtime/javaCalls.hpp" |
|
30 |
#include "runtime/handles.hpp" |
|
31 |
#include "jvmci/jvmciJavaClasses.hpp" |
|
32 |
#include "jvmci/jvmciCompiler.hpp" |
|
33 |
#include "jvmci/jvmciEnv.hpp" |
|
34 |
#include "jvmci/jvmciRuntime.hpp" |
|
35 |
#include "runtime/compilationPolicy.hpp" |
|
36 |
#include "runtime/globals_extension.hpp" |
|
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
47765
diff
changeset
|
37 |
#include "runtime/handles.inline.hpp" |
33160 | 38 |
|
39 |
JVMCICompiler* JVMCICompiler::_instance = NULL; |
|
40 |
elapsedTimer JVMCICompiler::_codeInstallTimer; |
|
41 |
||
42040
70ec5a09a0d5
8166377: is_compiled_by_jvmci hot in some profiles - improve nmethod compiler type detection
neliasso
parents:
41322
diff
changeset
|
42 |
JVMCICompiler::JVMCICompiler() : AbstractCompiler(compiler_jvmci) { |
33160 | 43 |
_bootstrapping = false; |
38674
eacc567feae8
8156034: [JVMCI] Notify the jvmci compiler on completion of a bootstrap
never
parents:
38666
diff
changeset
|
44 |
_bootstrap_compilation_request_handled = false; |
35845
30025047885d
8148507: [JVMCI] mitigate deadlocks related to JVMCI compiler under -Xbatch
dnsimon
parents:
35592
diff
changeset
|
45 |
_methods_compiled = 0; |
33160 | 46 |
assert(_instance == NULL, "only one instance allowed"); |
47 |
_instance = this; |
|
48 |
} |
|
49 |
||
50 |
// Initialization |
|
51 |
void JVMCICompiler::initialize() { |
|
52 |
if (!UseCompiler || !EnableJVMCI || !UseJVMCICompiler || !should_perform_init()) { |
|
53 |
return; |
|
54 |
} |
|
55 |
||
56 |
set_state(initialized); |
|
57 |
||
58 |
// JVMCI is considered as application code so we need to |
|
59 |
// stop the VM deferring compilation now. |
|
60 |
CompilationPolicy::completed_vm_startup(); |
|
61 |
} |
|
62 |
||
38674
eacc567feae8
8156034: [JVMCI] Notify the jvmci compiler on completion of a bootstrap
never
parents:
38666
diff
changeset
|
63 |
void JVMCICompiler::bootstrap(TRAPS) { |
33632 | 64 |
if (Arguments::mode() == Arguments::_int) { |
65 |
// Nothing to do in -Xint mode |
|
66 |
return; |
|
67 |
} |
|
33160 | 68 |
#ifndef PRODUCT |
69 |
// We turn off CompileTheWorld so that compilation requests are not |
|
70 |
// ignored during bootstrap or that JVMCI can be compiled by C1/C2. |
|
71 |
FlagSetting ctwOff(CompileTheWorld, false); |
|
72 |
#endif |
|
73 |
||
74 |
_bootstrapping = true; |
|
75 |
ResourceMark rm; |
|
76 |
HandleMark hm; |
|
77 |
if (PrintBootstrap) { |
|
78 |
tty->print("Bootstrapping JVMCI"); |
|
79 |
} |
|
80 |
jlong start = os::javaTimeMillis(); |
|
81 |
||
33602 | 82 |
Array<Method*>* objectMethods = SystemDictionary::Object_klass()->methods(); |
33160 | 83 |
// Initialize compile queue with a selected set of methods. |
84 |
int len = objectMethods->length(); |
|
85 |
for (int i = 0; i < len; i++) { |
|
86 |
methodHandle mh = objectMethods->at(i); |
|
87 |
if (!mh->is_native() && !mh->is_static() && !mh->is_initializer()) { |
|
88 |
ResourceMark rm; |
|
89 |
int hot_count = 10; // TODO: what's the appropriate value? |
|
38218 | 90 |
CompileBroker::compile_method(mh, InvocationEntryBci, CompLevel_full_optimization, mh, hot_count, CompileTask::Reason_Bootstrap, THREAD); |
33160 | 91 |
} |
92 |
} |
|
93 |
||
94 |
int qsize; |
|
95 |
bool first_round = true; |
|
96 |
int z = 0; |
|
97 |
do { |
|
98 |
// Loop until there is something in the queue. |
|
99 |
do { |
|
100 |
os::sleep(THREAD, 100, true); |
|
101 |
qsize = CompileBroker::queue_size(CompLevel_full_optimization); |
|
38674
eacc567feae8
8156034: [JVMCI] Notify the jvmci compiler on completion of a bootstrap
never
parents:
38666
diff
changeset
|
102 |
} while (!_bootstrap_compilation_request_handled && first_round && qsize == 0); |
33160 | 103 |
first_round = false; |
104 |
if (PrintBootstrap) { |
|
35845
30025047885d
8148507: [JVMCI] mitigate deadlocks related to JVMCI compiler under -Xbatch
dnsimon
parents:
35592
diff
changeset
|
105 |
while (z < (_methods_compiled / 100)) { |
33160 | 106 |
++z; |
107 |
tty->print_raw("."); |
|
108 |
} |
|
109 |
} |
|
110 |
} while (qsize != 0); |
|
111 |
||
112 |
if (PrintBootstrap) { |
|
35845
30025047885d
8148507: [JVMCI] mitigate deadlocks related to JVMCI compiler under -Xbatch
dnsimon
parents:
35592
diff
changeset
|
113 |
tty->print_cr(" in " JLONG_FORMAT " ms (compiled %d methods)", os::javaTimeMillis() - start, _methods_compiled); |
33160 | 114 |
} |
115 |
_bootstrapping = false; |
|
38674
eacc567feae8
8156034: [JVMCI] Notify the jvmci compiler on completion of a bootstrap
never
parents:
38666
diff
changeset
|
116 |
JVMCIRuntime::bootstrap_finished(CHECK); |
33160 | 117 |
} |
118 |
||
41322
d91c045cdfe4
8165755: [JVMCI] replace use of vm_abort with vm_exit
dnsimon
parents:
38695
diff
changeset
|
119 |
#define CHECK_EXIT THREAD); \ |
35143
33daaea9d5c2
8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents:
34185
diff
changeset
|
120 |
if (HAS_PENDING_EXCEPTION) { \ |
33daaea9d5c2
8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents:
34185
diff
changeset
|
121 |
char buf[256]; \ |
33daaea9d5c2
8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents:
34185
diff
changeset
|
122 |
jio_snprintf(buf, 256, "Uncaught exception at %s:%d", __FILE__, __LINE__); \ |
41322
d91c045cdfe4
8165755: [JVMCI] replace use of vm_abort with vm_exit
dnsimon
parents:
38695
diff
changeset
|
123 |
JVMCICompiler::exit_on_pending_exception(PENDING_EXCEPTION, buf); \ |
35143
33daaea9d5c2
8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents:
34185
diff
changeset
|
124 |
return; \ |
33daaea9d5c2
8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents:
34185
diff
changeset
|
125 |
} \ |
33daaea9d5c2
8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents:
34185
diff
changeset
|
126 |
(void)(0 |
33daaea9d5c2
8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents:
34185
diff
changeset
|
127 |
|
34165 | 128 |
void JVMCICompiler::compile_method(const methodHandle& method, int entry_bci, JVMCIEnv* env) { |
33160 | 129 |
JVMCI_EXCEPTION_CONTEXT |
130 |
||
131 |
bool is_osr = entry_bci != InvocationEntryBci; |
|
132 |
if (_bootstrapping && is_osr) { |
|
133 |
// no OSR compilations during bootstrap - the compiler is just too slow at this point, |
|
134 |
// and we know that there are no endless loops |
|
135 |
return; |
|
136 |
} |
|
137 |
||
41322
d91c045cdfe4
8165755: [JVMCI] replace use of vm_abort with vm_exit
dnsimon
parents:
38695
diff
changeset
|
138 |
JVMCIRuntime::initialize_well_known_classes(CHECK_EXIT); |
33160 | 139 |
|
140 |
HandleMark hm; |
|
41322
d91c045cdfe4
8165755: [JVMCI] replace use of vm_abort with vm_exit
dnsimon
parents:
38695
diff
changeset
|
141 |
Handle receiver = JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK_EXIT); |
33160 | 142 |
|
143 |
JavaValue method_result(T_OBJECT); |
|
33632 | 144 |
JavaCallArguments args; |
145 |
args.push_long((jlong) (address) method()); |
|
146 |
JavaCalls::call_static(&method_result, SystemDictionary::HotSpotResolvedJavaMethodImpl_klass(), |
|
147 |
vmSymbols::fromMetaspace_name(), vmSymbols::method_fromMetaspace_signature(), &args, THREAD); |
|
148 |
||
35592
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
35557
diff
changeset
|
149 |
JavaValue result(T_OBJECT); |
33632 | 150 |
if (!HAS_PENDING_EXCEPTION) { |
33160 | 151 |
JavaCallArguments args; |
33632 | 152 |
args.push_oop(receiver); |
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
42040
diff
changeset
|
153 |
args.push_oop(Handle(THREAD, (oop)method_result.get_jobject())); |
33632 | 154 |
args.push_int(entry_bci); |
155 |
args.push_long((jlong) (address) env); |
|
156 |
args.push_int(env->task()->compile_id()); |
|
157 |
JavaCalls::call_special(&result, receiver->klass(), |
|
158 |
vmSymbols::compileMethod_name(), vmSymbols::compileMethod_signature(), &args, THREAD); |
|
33160 | 159 |
} |
160 |
||
33632 | 161 |
// An uncaught exception was thrown during compilation. Generally these |
162 |
// should be handled by the Java code in some useful way but if they leak |
|
163 |
// through to here report them instead of dying or silently ignoring them. |
|
164 |
if (HAS_PENDING_EXCEPTION) { |
|
35143
33daaea9d5c2
8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents:
34185
diff
changeset
|
165 |
Handle exception(THREAD, PENDING_EXCEPTION); |
33632 | 166 |
CLEAR_PENDING_EXCEPTION; |
33160 | 167 |
|
35557
029dcb9bfa8b
8146246: JVMCICompiler::abort_on_pending_exception: assert(!thread->owns_locks()) failed: must release all locks when leaving VM
twisti
parents:
35143
diff
changeset
|
168 |
java_lang_Throwable::java_printStackTrace(exception, THREAD); |
36612
2191de2a73f1
8151871: [JVMCI] missing HAS_PENDING_EXCEPTION check
never
parents:
35845
diff
changeset
|
169 |
if (HAS_PENDING_EXCEPTION) { |
2191de2a73f1
8151871: [JVMCI] missing HAS_PENDING_EXCEPTION check
never
parents:
35845
diff
changeset
|
170 |
CLEAR_PENDING_EXCEPTION; |
2191de2a73f1
8151871: [JVMCI] missing HAS_PENDING_EXCEPTION check
never
parents:
35845
diff
changeset
|
171 |
} |
33632 | 172 |
|
35592
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
35557
diff
changeset
|
173 |
env->set_failure("exception throw", false); |
33632 | 174 |
} else { |
35592
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
35557
diff
changeset
|
175 |
oop result_object = (oop) result.get_jobject(); |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
35557
diff
changeset
|
176 |
if (result_object != NULL) { |
38695 | 177 |
oop failure_message = HotSpotCompilationRequestResult::failureMessage(result_object); |
35592
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
35557
diff
changeset
|
178 |
if (failure_message != NULL) { |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
35557
diff
changeset
|
179 |
const char* failure_reason = java_lang_String::as_utf8_string(failure_message); |
38695 | 180 |
env->set_failure(failure_reason, HotSpotCompilationRequestResult::retry(result_object) != 0); |
35592
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
35557
diff
changeset
|
181 |
} else { |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
35557
diff
changeset
|
182 |
if (env->task()->code() == NULL) { |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
35557
diff
changeset
|
183 |
env->set_failure("no nmethod produced", true); |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
35557
diff
changeset
|
184 |
} else { |
38695 | 185 |
env->task()->set_num_inlined_bytecodes(HotSpotCompilationRequestResult::inlinedBytecodes(result_object)); |
35845
30025047885d
8148507: [JVMCI] mitigate deadlocks related to JVMCI compiler under -Xbatch
dnsimon
parents:
35592
diff
changeset
|
186 |
Atomic::inc(&_methods_compiled); |
35592
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
35557
diff
changeset
|
187 |
} |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
35557
diff
changeset
|
188 |
} |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
35557
diff
changeset
|
189 |
} else { |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
35557
diff
changeset
|
190 |
assert(false, "JVMCICompiler.compileMethod should always return non-null"); |
5814f874d736
8147432: JVMCI should report bailouts in PrintCompilation output
never
parents:
35557
diff
changeset
|
191 |
} |
33632 | 192 |
} |
38674
eacc567feae8
8156034: [JVMCI] Notify the jvmci compiler on completion of a bootstrap
never
parents:
38666
diff
changeset
|
193 |
if (_bootstrapping) { |
eacc567feae8
8156034: [JVMCI] Notify the jvmci compiler on completion of a bootstrap
never
parents:
38666
diff
changeset
|
194 |
_bootstrap_compilation_request_handled = true; |
eacc567feae8
8156034: [JVMCI] Notify the jvmci compiler on completion of a bootstrap
never
parents:
38666
diff
changeset
|
195 |
} |
33160 | 196 |
} |
197 |
||
46727
6e4a84748e2c
8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents:
46560
diff
changeset
|
198 |
CompLevel JVMCIRuntime::adjust_comp_level(const methodHandle& method, bool is_osr, CompLevel level, JavaThread* thread) { |
38666
5ff19807abd5
8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents:
38218
diff
changeset
|
199 |
if (!thread->adjusting_comp_level()) { |
5ff19807abd5
8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents:
38218
diff
changeset
|
200 |
thread->set_adjusting_comp_level(true); |
5ff19807abd5
8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents:
38218
diff
changeset
|
201 |
level = adjust_comp_level_inner(method, is_osr, level, thread); |
5ff19807abd5
8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents:
38218
diff
changeset
|
202 |
thread->set_adjusting_comp_level(false); |
5ff19807abd5
8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents:
38218
diff
changeset
|
203 |
} |
5ff19807abd5
8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents:
38218
diff
changeset
|
204 |
return level; |
5ff19807abd5
8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents:
38218
diff
changeset
|
205 |
} |
5ff19807abd5
8152311: [JVMCI] allow JVMCI compiler to change the compilation policy for a method
dnsimon
parents:
38218
diff
changeset
|
206 |
|
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
42040
diff
changeset
|
207 |
void JVMCICompiler::exit_on_pending_exception(oop exception, const char* message) { |
41322
d91c045cdfe4
8165755: [JVMCI] replace use of vm_abort with vm_exit
dnsimon
parents:
38695
diff
changeset
|
208 |
JavaThread* THREAD = JavaThread::current(); |
35143
33daaea9d5c2
8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents:
34185
diff
changeset
|
209 |
CLEAR_PENDING_EXCEPTION; |
33daaea9d5c2
8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents:
34185
diff
changeset
|
210 |
|
41322
d91c045cdfe4
8165755: [JVMCI] replace use of vm_abort with vm_exit
dnsimon
parents:
38695
diff
changeset
|
211 |
static volatile int report_error = 0; |
d91c045cdfe4
8165755: [JVMCI] replace use of vm_abort with vm_exit
dnsimon
parents:
38695
diff
changeset
|
212 |
if (!report_error && Atomic::cmpxchg(1, &report_error, 0) == 0) { |
d91c045cdfe4
8165755: [JVMCI] replace use of vm_abort with vm_exit
dnsimon
parents:
38695
diff
changeset
|
213 |
// Only report an error once |
d91c045cdfe4
8165755: [JVMCI] replace use of vm_abort with vm_exit
dnsimon
parents:
38695
diff
changeset
|
214 |
tty->print_raw_cr(message); |
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
42040
diff
changeset
|
215 |
Handle ex(THREAD, exception); |
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
42040
diff
changeset
|
216 |
java_lang_Throwable::java_printStackTrace(ex, THREAD); |
41322
d91c045cdfe4
8165755: [JVMCI] replace use of vm_abort with vm_exit
dnsimon
parents:
38695
diff
changeset
|
217 |
} else { |
50858 | 218 |
// Allow error reporting thread to print the stack trace. Windows |
219 |
// doesn't allow uninterruptible wait for JavaThreads |
|
220 |
const bool interruptible = true; |
|
221 |
os::sleep(THREAD, 200, interruptible); |
|
41322
d91c045cdfe4
8165755: [JVMCI] replace use of vm_abort with vm_exit
dnsimon
parents:
38695
diff
changeset
|
222 |
} |
35143
33daaea9d5c2
8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents:
34185
diff
changeset
|
223 |
|
41322
d91c045cdfe4
8165755: [JVMCI] replace use of vm_abort with vm_exit
dnsimon
parents:
38695
diff
changeset
|
224 |
before_exit(THREAD); |
d91c045cdfe4
8165755: [JVMCI] replace use of vm_abort with vm_exit
dnsimon
parents:
38695
diff
changeset
|
225 |
vm_exit(-1); |
35143
33daaea9d5c2
8145435: [JVMCI] some tests on Windows fail with: assert(!thread->is_Java_thread()) failed: must not be java thread
twisti
parents:
34185
diff
changeset
|
226 |
} |
33160 | 227 |
|
228 |
// Compilation entry point for methods |
|
33451
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
33160
diff
changeset
|
229 |
void JVMCICompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci, DirectiveSet* directive) { |
33160 | 230 |
ShouldNotReachHere(); |
231 |
} |
|
232 |
||
233 |
// Print compilation timers and statistics |
|
234 |
void JVMCICompiler::print_timers() { |
|
235 |
print_compilation_timers(); |
|
236 |
} |
|
237 |
||
238 |
// Print compilation timers and statistics |
|
239 |
void JVMCICompiler::print_compilation_timers() { |
|
240 |
TRACE_jvmci_1("JVMCICompiler::print_timers"); |
|
241 |
tty->print_cr(" JVMCI code install time: %6.3f s", _codeInstallTimer.seconds()); |
|
242 |
} |