author | aph |
Wed, 13 Jan 2016 15:57:42 +0000 | |
changeset 35561 | 43eaa2fed344 |
parent 35557 | 029dcb9bfa8b |
child 35592 | 5814f874d736 |
permissions | -rw-r--r-- |
33160 | 1 |
/* |
33602 | 2 |
* Copyright (c) 2011, 2015, 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" |
|
25 |
#include "memory/oopFactory.hpp" |
|
26 |
#include "oops/oop.inline.hpp" |
|
27 |
#include "runtime/javaCalls.hpp" |
|
28 |
#include "runtime/handles.hpp" |
|
29 |
#include "jvmci/jvmciJavaClasses.hpp" |
|
30 |
#include "jvmci/jvmciCompiler.hpp" |
|
31 |
#include "jvmci/jvmciEnv.hpp" |
|
32 |
#include "jvmci/jvmciRuntime.hpp" |
|
33 |
#include "runtime/compilationPolicy.hpp" |
|
34 |
#include "runtime/globals_extension.hpp" |
|
35 |
||
36 |
JVMCICompiler* JVMCICompiler::_instance = NULL; |
|
37 |
elapsedTimer JVMCICompiler::_codeInstallTimer; |
|
38 |
||
39 |
JVMCICompiler::JVMCICompiler() : AbstractCompiler(jvmci) { |
|
40 |
_bootstrapping = false; |
|
41 |
_methodsCompiled = 0; |
|
42 |
assert(_instance == NULL, "only one instance allowed"); |
|
43 |
_instance = this; |
|
44 |
} |
|
45 |
||
46 |
// Initialization |
|
47 |
void JVMCICompiler::initialize() { |
|
48 |
if (!UseCompiler || !EnableJVMCI || !UseJVMCICompiler || !should_perform_init()) { |
|
49 |
return; |
|
50 |
} |
|
51 |
||
52 |
set_state(initialized); |
|
53 |
||
54 |
// JVMCI is considered as application code so we need to |
|
55 |
// stop the VM deferring compilation now. |
|
56 |
CompilationPolicy::completed_vm_startup(); |
|
57 |
} |
|
58 |
||
59 |
void JVMCICompiler::bootstrap() { |
|
33632 | 60 |
if (Arguments::mode() == Arguments::_int) { |
61 |
// Nothing to do in -Xint mode |
|
62 |
return; |
|
63 |
} |
|
33160 | 64 |
#ifndef PRODUCT |
65 |
// We turn off CompileTheWorld so that compilation requests are not |
|
66 |
// ignored during bootstrap or that JVMCI can be compiled by C1/C2. |
|
67 |
FlagSetting ctwOff(CompileTheWorld, false); |
|
68 |
#endif |
|
69 |
||
70 |
JavaThread* THREAD = JavaThread::current(); |
|
71 |
_bootstrapping = true; |
|
72 |
ResourceMark rm; |
|
73 |
HandleMark hm; |
|
74 |
if (PrintBootstrap) { |
|
75 |
tty->print("Bootstrapping JVMCI"); |
|
76 |
} |
|
77 |
jlong start = os::javaTimeMillis(); |
|
78 |
||
33602 | 79 |
Array<Method*>* objectMethods = SystemDictionary::Object_klass()->methods(); |
33160 | 80 |
// Initialize compile queue with a selected set of methods. |
81 |
int len = objectMethods->length(); |
|
82 |
for (int i = 0; i < len; i++) { |
|
83 |
methodHandle mh = objectMethods->at(i); |
|
84 |
if (!mh->is_native() && !mh->is_static() && !mh->is_initializer()) { |
|
85 |
ResourceMark rm; |
|
86 |
int hot_count = 10; // TODO: what's the appropriate value? |
|
87 |
CompileBroker::compile_method(mh, InvocationEntryBci, CompLevel_full_optimization, mh, hot_count, "bootstrap", THREAD); |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
int qsize; |
|
92 |
bool first_round = true; |
|
93 |
int z = 0; |
|
94 |
do { |
|
95 |
// Loop until there is something in the queue. |
|
96 |
do { |
|
97 |
os::sleep(THREAD, 100, true); |
|
98 |
qsize = CompileBroker::queue_size(CompLevel_full_optimization); |
|
99 |
} while (first_round && qsize == 0); |
|
100 |
first_round = false; |
|
101 |
if (PrintBootstrap) { |
|
102 |
while (z < (_methodsCompiled / 100)) { |
|
103 |
++z; |
|
104 |
tty->print_raw("."); |
|
105 |
} |
|
106 |
} |
|
107 |
} while (qsize != 0); |
|
108 |
||
109 |
if (PrintBootstrap) { |
|
110 |
tty->print_cr(" in " JLONG_FORMAT " ms (compiled %d methods)", os::javaTimeMillis() - start, _methodsCompiled); |
|
111 |
} |
|
112 |
_bootstrapping = false; |
|
113 |
} |
|
114 |
||
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
|
115 |
#define CHECK_ABORT THREAD); \ |
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
|
116 |
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
|
117 |
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
|
118 |
jio_snprintf(buf, 256, "Uncaught exception at %s:%d", __FILE__, __LINE__); \ |
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
|
119 |
JVMCICompiler::abort_on_pending_exception(PENDING_EXCEPTION, buf); \ |
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 |
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
|
121 |
} \ |
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 |
(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
|
123 |
|
34165 | 124 |
void JVMCICompiler::compile_method(const methodHandle& method, int entry_bci, JVMCIEnv* env) { |
33160 | 125 |
JVMCI_EXCEPTION_CONTEXT |
126 |
||
127 |
bool is_osr = entry_bci != InvocationEntryBci; |
|
128 |
if (_bootstrapping && is_osr) { |
|
129 |
// no OSR compilations during bootstrap - the compiler is just too slow at this point, |
|
130 |
// and we know that there are no endless loops |
|
131 |
return; |
|
132 |
} |
|
133 |
||
134 |
JVMCIRuntime::initialize_well_known_classes(CHECK_ABORT); |
|
135 |
||
136 |
HandleMark hm; |
|
137 |
ResourceMark rm; |
|
138 |
Handle receiver = JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK_ABORT); |
|
139 |
||
140 |
JavaValue method_result(T_OBJECT); |
|
33632 | 141 |
JavaCallArguments args; |
142 |
args.push_long((jlong) (address) method()); |
|
143 |
JavaCalls::call_static(&method_result, SystemDictionary::HotSpotResolvedJavaMethodImpl_klass(), |
|
144 |
vmSymbols::fromMetaspace_name(), vmSymbols::method_fromMetaspace_signature(), &args, THREAD); |
|
145 |
||
146 |
if (!HAS_PENDING_EXCEPTION) { |
|
147 |
JavaValue result(T_VOID); |
|
33160 | 148 |
JavaCallArguments args; |
33632 | 149 |
args.push_oop(receiver); |
150 |
args.push_oop((oop)method_result.get_jobject()); |
|
151 |
args.push_int(entry_bci); |
|
152 |
args.push_long((jlong) (address) env); |
|
153 |
args.push_int(env->task()->compile_id()); |
|
154 |
JavaCalls::call_special(&result, receiver->klass(), |
|
155 |
vmSymbols::compileMethod_name(), vmSymbols::compileMethod_signature(), &args, THREAD); |
|
33160 | 156 |
} |
157 |
||
33632 | 158 |
// An uncaught exception was thrown during compilation. Generally these |
159 |
// should be handled by the Java code in some useful way but if they leak |
|
160 |
// through to here report them instead of dying or silently ignoring them. |
|
161 |
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
|
162 |
Handle exception(THREAD, PENDING_EXCEPTION); |
33632 | 163 |
CLEAR_PENDING_EXCEPTION; |
33160 | 164 |
|
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
|
165 |
java_lang_Throwable::java_printStackTrace(exception, THREAD); |
33632 | 166 |
|
167 |
// Something went wrong so disable compilation at this level |
|
168 |
method->set_not_compilable(CompLevel_full_optimization); |
|
169 |
} else { |
|
170 |
_methodsCompiled++; |
|
171 |
} |
|
33160 | 172 |
} |
173 |
||
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
|
174 |
/** |
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
|
175 |
* Aborts the VM due to an unexpected 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
|
176 |
*/ |
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
|
177 |
void JVMCICompiler::abort_on_pending_exception(Handle exception, const char* message, bool dump_core) { |
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
|
178 |
Thread* THREAD = Thread::current(); |
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
|
179 |
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
|
180 |
|
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
|
181 |
java_lang_Throwable::java_printStackTrace(exception, 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
|
182 |
|
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
|
183 |
// Give other aborting threads to also print their stack traces. |
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
|
184 |
// This can be very useful when debugging class initialization |
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
|
185 |
// failures. |
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
|
186 |
assert(THREAD->is_Java_thread(), "compiler threads should be Java threads"); |
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
|
187 |
const bool interruptible = true; |
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
|
188 |
os::sleep(THREAD, 200, interruptible); |
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
|
189 |
|
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
|
190 |
vm_abort(dump_core); |
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
|
191 |
} |
33160 | 192 |
|
193 |
// Compilation entry point for methods |
|
33451
0712796e4039
8137167: JEP165: Compiler Control: Implementation task
neliasso
parents:
33160
diff
changeset
|
194 |
void JVMCICompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci, DirectiveSet* directive) { |
33160 | 195 |
ShouldNotReachHere(); |
196 |
} |
|
197 |
||
33632 | 198 |
bool JVMCICompiler::is_trivial(Method* method) { |
199 |
if (_bootstrapping) { |
|
200 |
return false; |
|
201 |
} |
|
202 |
return JVMCIRuntime::treat_as_trivial(method); |
|
203 |
} |
|
204 |
||
33160 | 205 |
// Print compilation timers and statistics |
206 |
void JVMCICompiler::print_timers() { |
|
207 |
print_compilation_timers(); |
|
208 |
} |
|
209 |
||
210 |
// Print compilation timers and statistics |
|
211 |
void JVMCICompiler::print_compilation_timers() { |
|
212 |
TRACE_jvmci_1("JVMCICompiler::print_timers"); |
|
213 |
tty->print_cr(" JVMCI code install time: %6.3f s", _codeInstallTimer.seconds()); |
|
214 |
} |