comparison src/share/vm/jvmci/jvmciCompiler.cpp @ 21559:be896a1983c0

recast all Graal native code as JVMCI code (JBS:GRAAL-53)
author Doug Simon <doug.simon@oracle.com>
date Thu, 28 May 2015 15:36:48 +0200
parents src/share/vm/graal/graalCompiler.cpp@5324104ac4f3
children 4c146c9367b6
comparison
equal deleted inserted replaced
21558:d563baeca9df 21559:be896a1983c0
1 /*
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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 "runtime/javaCalls.hpp"
27 #include "jvmci/jvmciCompiler.hpp"
28 #include "jvmci/jvmciEnv.hpp"
29 #include "jvmci/jvmciRuntime.hpp"
30 #include "runtime/compilationPolicy.hpp"
31 #include "runtime/globals_extension.hpp"
32
33 JVMCICompiler* JVMCICompiler::_instance = NULL;
34 elapsedTimer JVMCICompiler::_codeInstallTimer;
35
36 JVMCICompiler::JVMCICompiler() : AbstractCompiler(jvmci) {
37 #ifdef COMPILERJVMCI
38 _bootstrapping = false;
39 _methodsCompiled = 0;
40 #endif
41 assert(_instance == NULL, "only one instance allowed");
42 _instance = this;
43 }
44
45 // Initialization
46 void JVMCICompiler::initialize() {
47 #ifdef COMPILERJVMCI
48 if (!UseCompiler || !should_perform_init()) {
49 return;
50 }
51
52 BufferBlob* buffer_blob = JVMCIRuntime::initialize_buffer_blob();
53 if (buffer_blob == NULL) {
54 set_state(failed);
55 } else {
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 #endif // COMPILERJVMCI
62 }
63
64 #ifdef COMPILERJVMCI
65 void JVMCICompiler::bootstrap() {
66 JavaThread* THREAD = JavaThread::current();
67 _bootstrapping = true;
68 // Allow bootstrap to perform JVMCI compilations of itself
69 bool c1only = JVMCICompileWithC1Only;
70 JVMCICompileWithC1Only = false;
71 ResourceMark rm;
72 HandleMark hm;
73 if (PrintBootstrap) {
74 tty->print("Bootstrapping JVMCI");
75 }
76 jlong start = os::javaTimeMillis();
77
78 Array<Method*>* objectMethods = InstanceKlass::cast(SystemDictionary::Object_klass())->methods();
79 // Initialize compile queue with a selected set of methods.
80 int len = objectMethods->length();
81 for (int i = 0; i < len; i++) {
82 methodHandle mh = objectMethods->at(i);
83 if (!mh->is_native() && !mh->is_static() && !mh->is_initializer()) {
84 ResourceMark rm;
85 int hot_count = 10; // TODO: what's the appropriate value?
86 CompileBroker::compile_method(mh, InvocationEntryBci, CompLevel_full_optimization, mh, hot_count, "bootstrap", THREAD);
87 }
88 }
89
90 int qsize;
91 bool first_round = true;
92 int z = 0;
93 do {
94 // Loop until there is something in the queue.
95 do {
96 os::sleep(THREAD, 100, true);
97 qsize = CompileBroker::queue_size(CompLevel_full_optimization);
98 } while (first_round && qsize == 0);
99 first_round = false;
100 if (PrintBootstrap) {
101 while (z < (_methodsCompiled / 100)) {
102 ++z;
103 tty->print_raw(".");
104 }
105 }
106 } while (qsize != 0);
107
108 if (PrintBootstrap) {
109 tty->print_cr(" in " JLONG_FORMAT " ms (compiled %d methods)", os::javaTimeMillis() - start, _methodsCompiled);
110 }
111 JVMCICompileWithC1Only = c1only;
112 _bootstrapping = false;
113 }
114
115 void JVMCICompiler::compile_method(methodHandle method, int entry_bci, JVMCIEnv* env) {
116 JVMCI_EXCEPTION_CONTEXT
117
118 bool is_osr = entry_bci != InvocationEntryBci;
119 if (_bootstrapping && is_osr) {
120 // no OSR compilations during bootstrap - the compiler is just too slow at this point,
121 // and we know that there are no endless loops
122 return;
123 }
124
125 JVMCIRuntime::ensure_jvmci_class_loader_is_initialized();
126 HandleMark hm;
127 ResourceMark rm;
128 JavaValue result(T_VOID);
129 JavaCallArguments args;
130 args.push_long((jlong) (address) method());
131 args.push_int(entry_bci);
132 args.push_long((jlong) (address) env);
133 args.push_int(env->task()->compile_id());
134 JavaCalls::call_static(&result, SystemDictionary::CompilationTask_klass(), vmSymbols::compileMetaspaceMethod_name(), vmSymbols::compileMetaspaceMethod_signature(), &args, CHECK_ABORT);
135
136 _methodsCompiled++;
137 }
138
139
140 // Compilation entry point for methods
141 void JVMCICompiler::compile_method(ciEnv* env, ciMethod* target, int entry_bci) {
142 ShouldNotReachHere();
143 }
144
145 // Print compilation timers and statistics
146 void JVMCICompiler::print_timers() {
147 print_compilation_timers();
148 }
149
150 #endif // COMPILERJVMCI
151
152 // Print compilation timers and statistics
153 void JVMCICompiler::print_compilation_timers() {
154 TRACE_jvmci_1("JVMCICompiler::print_timers");
155 tty->print_cr(" JVMCI code install time: %6.3f s", _codeInstallTimer.seconds());
156 }
157
158 void JVMCICompiler::compile_the_world() {
159 HandleMark hm;
160 JavaThread* THREAD = JavaThread::current();
161 TempNewSymbol name = SymbolTable::new_symbol("com/oracle/jvmci/hotspot/HotSpotJVMCIRuntime", CHECK_ABORT);
162 KlassHandle klass = JVMCIRuntime::load_required_class(name);
163 TempNewSymbol compileTheWorld = SymbolTable::new_symbol("compileTheWorld", CHECK_ABORT);
164 JavaValue result(T_VOID);
165 JavaCallArguments args;
166 args.push_oop(JVMCIRuntime::get_HotSpotJVMCIRuntime());
167 JavaCalls::call_special(&result, klass, compileTheWorld, vmSymbols::void_method_signature(), &args, CHECK_ABORT);
168 }