comparison src/share/vm/graal/graalVMEntries.cpp @ 2890:c23d45daff9b

Renamed cpp/hpp file directory.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 08 Jun 2011 13:40:25 +0200
parents src/share/vm/c1x/graalVMEntries.cpp@2fb867285938
children 75a99b4f1c98
comparison
equal deleted inserted replaced
2889:2fb867285938 2890:c23d45daff9b
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 "c1x/c1x_VMEntries.hpp"
26 #include "c1x/c1x_Compiler.hpp"
27 #include "c1x/c1x_JavaAccess.hpp"
28 #include "c1x/c1x_CodeInstaller.hpp"
29 #include "c1x/c1x_VMExits.hpp"
30 #include "c1x/c1x_VmIds.hpp"
31 #include "c1/c1_Runtime1.hpp"
32 #include "memory/oopFactory.hpp"
33
34 // public byte[] RiMethod_code(long vmId);
35 JNIEXPORT jbyteArray JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_1code(JNIEnv *env, jobject, jlong vmId) {
36 TRACE_C1X_3("VMEntries::RiMethod_code");
37 methodHandle method = VmIds::get<methodOop>(vmId);
38 int code_size = method->code_size();
39 jbyteArray result = env->NewByteArray(code_size);
40 env->SetByteArrayRegion(result, 0, code_size, (const jbyte *) method->code_base());
41 return result;
42 }
43
44 // public int RiMethod_maxStackSize(long vmId);
45 JNIEXPORT jint JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_1maxStackSize(JNIEnv *, jobject, jlong vmId) {
46 TRACE_C1X_3("VMEntries::RiMethod_maxStackSize");
47 return VmIds::get<methodOop>(vmId)->max_stack();
48 }
49
50 // public int RiMethod_maxLocals(long vmId);
51 JNIEXPORT jint JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_1maxLocals(JNIEnv *, jobject, jlong vmId) {
52 TRACE_C1X_3("VMEntries::RiMethod_maxLocals");
53 return VmIds::get<methodOop>(vmId)->max_locals();
54 }
55
56 // public RiType RiMethod_holder(long vmId);
57 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_1holder(JNIEnv *, jobject, jlong vmId) {
58 TRACE_C1X_3("VMEntries::RiMethod_holder");
59 VM_ENTRY_MARK
60 KlassHandle klass = VmIds::get<methodOop>(vmId)->method_holder();
61 Handle name = VmIds::toString<Handle>(klass->name(), CHECK_NULL);
62 oop holder = C1XCompiler::createHotSpotTypeResolved(klass, name, CHECK_NULL);
63 return JNIHandles::make_local(THREAD, holder);
64 }
65
66 // public String RiMethod_signature(long vmId);
67 JNIEXPORT jstring JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_1signature(JNIEnv *env, jobject, jlong vmId) {
68 TRACE_C1X_3("VMEntries::RiMethod_signature");
69 VM_ENTRY_MARK
70 methodOop method = VmIds::get<methodOop>(vmId);
71 return VmIds::toString<jstring>(method->signature(), THREAD);
72 }
73
74 // public int RiMethod_accessFlags(long vmId);
75 JNIEXPORT jint JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_1accessFlags(JNIEnv *, jobject, jlong vmId) {
76 TRACE_C1X_3("VMEntries::RiMethod_accessFlags");
77 return VmIds::get<methodOop>(vmId)->access_flags().as_int();
78 }
79
80 // public RiExceptionHandler[] RiMethod_exceptionHandlers(long vmId);
81 JNIEXPORT jobjectArray JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_1exceptionHandlers(JNIEnv *, jobject, jlong vmId) {
82 TRACE_C1X_3("VMEntries::RiMethod_exceptionHandlers");
83 VM_ENTRY_MARK
84 methodHandle method = VmIds::get<methodOop>(vmId);
85 typeArrayHandle handlers = method->exception_table();
86 int handler_count = handlers.is_null() ? 0 : handlers->length() / 4;
87
88 instanceKlass::cast(HotSpotExceptionHandler::klass())->initialize(CHECK_NULL);
89 objArrayHandle array = oopFactory::new_objArray(SystemDictionary::RiExceptionHandler_klass(), handler_count, CHECK_NULL);
90
91 for (int i = 0; i < handler_count; i++) {
92 // exception handlers are stored as four integers: start bci, end bci, handler bci, catch class constant pool index
93 int base = i * 4;
94 Handle entry = instanceKlass::cast(HotSpotExceptionHandler::klass())->allocate_instance(CHECK_NULL);
95 HotSpotExceptionHandler::set_startBci(entry, handlers->int_at(base + 0));
96 HotSpotExceptionHandler::set_endBci(entry, handlers->int_at(base + 1));
97 HotSpotExceptionHandler::set_handlerBci(entry, handlers->int_at(base + 2));
98 int catch_class_index = handlers->int_at(base + 3);
99 HotSpotExceptionHandler::set_catchClassIndex(entry, catch_class_index);
100
101 if (catch_class_index == 0) {
102 HotSpotExceptionHandler::set_catchClass(entry, NULL);
103 } else {
104 constantPoolOop cp = instanceKlass::cast(method->method_holder())->constants();
105 ciInstanceKlass* loading_klass = (ciInstanceKlass *) CURRENT_ENV->get_object(method->method_holder());
106 bool is_accessible = false;
107 ciKlass *klass = CURRENT_ENV->get_klass_by_index(cp, catch_class_index, is_accessible, loading_klass);
108 oop catch_class = C1XCompiler::get_RiType(klass, method->method_holder(), CHECK_NULL);
109
110 HotSpotExceptionHandler::set_catchClass(entry, catch_class);
111 }
112 array->obj_at_put(i, entry());
113 }
114
115 return (jobjectArray) JNIHandles::make_local(array());
116 }
117
118 // public boolean RiMethod_hasBalancedMonitors(long vmId);
119 JNIEXPORT jint JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_1hasBalancedMonitors(JNIEnv *, jobject, jlong vmId) {
120 TRACE_C1X_3("VMEntries::RiMethod_hasBalancedMonitors");
121 ciMethod* cimethod;
122 {
123 VM_ENTRY_MARK;
124 cimethod = (ciMethod*)CURRENT_ENV->get_object(VmIds::get<methodOop>(vmId));
125 }
126 return cimethod->has_balanced_monitors();
127 }
128
129 // public boolean RiMethod_uniqueConcreteMethod(long vmId);
130 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_1uniqueConcreteMethod(JNIEnv *, jobject, jlong vmId) {
131 TRACE_C1X_3("VMEntries::RiMethod_uniqueConcreteMethod");
132 VM_ENTRY_MARK;
133 ciMethod* cimethod = (ciMethod*)CURRENT_ENV->get_object(VmIds::get<methodOop>(vmId));
134 if (cimethod->holder()->is_interface()) {
135 // Cannot trust interfaces. Because of:
136 // interface I { void foo(); }
137 // class A { public void foo() {} }
138 // class B extends A implements I { }
139 // class C extends B { public void foo() { } }
140 // class D extends B { }
141 // Would lead to identify C.foo() as the unique concrete method for I.foo() without seeing A.foo().
142 return false;
143 }
144 klassOop klass = (klassOop)cimethod->holder()->get_oop();
145 methodHandle method((methodOop)cimethod->get_oop());
146 methodHandle unique_concrete;
147 {
148 ResourceMark rm;
149 MutexLocker locker(Compile_lock);
150 unique_concrete = methodHandle(Dependencies::find_unique_concrete_method(klass, method()));
151 }
152 if (unique_concrete.is_null()) {
153 return NULL;
154 }
155
156 Handle name = VmIds::toString<Handle>(unique_concrete->name(), CHECK_NULL);
157 oop method_resolved = VMExits::createRiMethodResolved(VmIds::add<methodOop>(unique_concrete()), name, CHECK_NULL);
158 return JNIHandles::make_local(THREAD, method_resolved);
159 }
160
161 // public RiType RiSignature_lookupType(String returnType, HotSpotTypeResolved accessingClass);
162 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiSignature_1lookupType(JNIEnv *env, jobject, jstring jname, jobject accessingClass) {
163 TRACE_C1X_3("VMEntries::RiSignature_lookupType");
164 VM_ENTRY_MARK;
165
166 Symbol* nameSymbol = VmIds::toSymbol(jname);
167 Handle name = JNIHandles::resolve(jname);
168
169 oop result;
170 if (nameSymbol == vmSymbols::int_signature()) {
171 result = VMExits::createRiTypePrimitive((int) T_INT, THREAD);
172 } else if (nameSymbol == vmSymbols::long_signature()) {
173 result = VMExits::createRiTypePrimitive((int) T_LONG, THREAD);
174 } else if (nameSymbol == vmSymbols::bool_signature()) {
175 result = VMExits::createRiTypePrimitive((int) T_BOOLEAN, THREAD);
176 } else if (nameSymbol == vmSymbols::char_signature()) {
177 result = VMExits::createRiTypePrimitive((int) T_CHAR, THREAD);
178 } else if (nameSymbol == vmSymbols::short_signature()) {
179 result = VMExits::createRiTypePrimitive((int) T_SHORT, THREAD);
180 } else if (nameSymbol == vmSymbols::byte_signature()) {
181 result = VMExits::createRiTypePrimitive((int) T_BYTE, THREAD);
182 } else if (nameSymbol == vmSymbols::double_signature()) {
183 result = VMExits::createRiTypePrimitive((int) T_DOUBLE, THREAD);
184 } else if (nameSymbol == vmSymbols::float_signature()) {
185 result = VMExits::createRiTypePrimitive((int) T_FLOAT, THREAD);
186 } else {
187 klassOop resolved_type = NULL;
188 // if the name isn't in the symbol table then the class isn't loaded anyway...
189 if (nameSymbol != NULL) {
190 Handle classloader;
191 Handle protectionDomain;
192 if (JNIHandles::resolve(accessingClass) != NULL) {
193 classloader = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(accessingClass))->klass_part()->class_loader();
194 protectionDomain = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(accessingClass))->klass_part()->protection_domain();
195 }
196 resolved_type = SystemDictionary::resolve_or_null(nameSymbol, classloader, protectionDomain, THREAD);
197 if (HAS_PENDING_EXCEPTION) {
198 CLEAR_PENDING_EXCEPTION;
199 resolved_type = NULL;
200 }
201 }
202 if (resolved_type != NULL) {
203 result = C1XCompiler::createHotSpotTypeResolved(resolved_type, name, CHECK_NULL);
204 } else {
205 result = VMExits::createRiTypeUnresolved(name, THREAD);
206 }
207 }
208
209 return JNIHandles::make_local(THREAD, result);
210 }
211
212 // public Object RiConstantPool_lookupConstant(long vmId, int cpi);
213 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupConstant(JNIEnv *env, jobject, jlong vmId, jint index) {
214 TRACE_C1X_3("VMEntries::RiConstantPool_lookupConstant");
215 VM_ENTRY_MARK;
216
217 constantPoolOop cp = VmIds::get<constantPoolOop>(vmId);
218
219 oop result = NULL;
220 constantTag tag = cp->tag_at(index);
221 if (tag.is_int()) {
222 result = VMExits::createCiConstant(CiKind::Int(), cp->int_at(index), CHECK_0);
223 } else if (tag.is_long()) {
224 result = VMExits::createCiConstant(CiKind::Long(), cp->long_at(index), CHECK_0);
225 } else if (tag.is_float()) {
226 result = VMExits::createCiConstantFloat(cp->float_at(index), CHECK_0);
227 } else if (tag.is_double()) {
228 result = VMExits::createCiConstantDouble(cp->double_at(index), CHECK_0);
229 } else if (tag.is_string() || tag.is_unresolved_string()) {
230 oop string = NULL;
231 if (cp->is_pseudo_string_at(index)) {
232 string = cp->pseudo_string_at(index);
233 } else {
234 string = cp->string_at(index, THREAD);
235 if (HAS_PENDING_EXCEPTION) {
236 CLEAR_PENDING_EXCEPTION;
237 // TODO: Gracefully exit compilation.
238 fatal("out of memory during compilation!");
239 return NULL;
240 }
241 }
242 result = VMExits::createCiConstantObject(string, CHECK_0);
243 } else if (tag.is_klass() || tag.is_unresolved_klass()) {
244 bool ignore;
245 ciInstanceKlass* accessor = (ciInstanceKlass*) ciEnv::current()->get_object(cp->pool_holder());
246 ciKlass* klass = ciEnv::current()->get_klass_by_index(cp, index, ignore, accessor);
247 result = C1XCompiler::get_RiType(klass, cp->pool_holder(), CHECK_NULL);
248 } else if (tag.is_object()) {
249 oop obj = cp->object_at(index);
250 assert(obj->is_instance(), "must be an instance");
251 result = VMExits::createCiConstantObject(obj, CHECK_NULL);
252 } else {
253 ShouldNotReachHere();
254 }
255
256 return JNIHandles::make_local(THREAD, result);
257 }
258
259 // public RiMethod RiConstantPool_lookupMethod(long vmId, int cpi, byte byteCode);
260 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupMethod(JNIEnv *env, jobject, jlong vmId, jint index, jbyte byteCode) {
261 TRACE_C1X_3("VMEntries::RiConstantPool_lookupMethod");
262 VM_ENTRY_MARK;
263
264 index = C1XCompiler::to_cp_index_u2(index);
265 constantPoolHandle cp = VmIds::get<constantPoolOop>(vmId);
266
267 Bytecodes::Code bc = (Bytecodes::Code) (((int) byteCode) & 0xFF);
268 ciInstanceKlass* loading_klass = (ciInstanceKlass *) CURRENT_ENV->get_object(cp->pool_holder());
269 ciMethod *cimethod = CURRENT_ENV->get_method_by_index(cp, index, bc, loading_klass);
270 if (cimethod->is_loaded()) {
271 methodOop method = (methodOop) cimethod->get_oop();
272 Handle name = VmIds::toString<Handle>(method->name(), CHECK_NULL);
273 return JNIHandles::make_local(THREAD, VMExits::createRiMethodResolved(VmIds::add<methodOop>(method), name, THREAD));
274 } else {
275 Handle name = VmIds::toString<Handle>(cimethod->name()->get_symbol(), CHECK_NULL);
276 Handle signature = VmIds::toString<Handle>(cimethod->signature()->as_symbol()->get_symbol(), CHECK_NULL);
277 Handle holder = C1XCompiler::get_RiType(cimethod->holder(), cp->klass(), THREAD);
278 return JNIHandles::make_local(THREAD, VMExits::createRiMethodUnresolved(name, signature, holder, THREAD));
279 }
280 }
281
282 // public RiSignature RiConstantPool_lookupSignature(long vmId, int cpi);
283 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupSignature(JNIEnv *env, jobject, jlong vmId, jint index) {
284 fatal("currently unsupported");
285 return NULL;
286 }
287
288 // public RiType RiConstantPool_lookupType(long vmId, int cpi);
289 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupType(JNIEnv *env, jobject, jlong vmId, jint index) {
290 TRACE_C1X_3("VMEntries::RiConstantPool_lookupType");
291 VM_ENTRY_MARK;
292
293 constantPoolOop cp = VmIds::get<constantPoolOop>(vmId);
294
295 ciInstanceKlass* loading_klass = (ciInstanceKlass *) CURRENT_ENV->get_object(cp->pool_holder());
296 bool is_accessible = false;
297 ciKlass *klass = CURRENT_ENV->get_klass_by_index(cp, index, is_accessible, loading_klass);
298 return JNIHandles::make_local(THREAD, C1XCompiler::get_RiType(klass, cp->klass(), THREAD));
299 }
300
301 // public RiField RiConstantPool_lookupField(long vmId, int cpi);
302 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupField(JNIEnv *env, jobject, jlong vmId, jint index, jbyte byteCode) {
303 TRACE_C1X_3("VMEntries::RiConstantPool_lookupField");
304 VM_ENTRY_MARK;
305
306 index = C1XCompiler::to_cp_index_u2(index);
307 constantPoolOop cp = VmIds::get<constantPoolOop>(vmId);
308
309 ciInstanceKlass* loading_klass = (ciInstanceKlass *) CURRENT_ENV->get_object(cp->pool_holder());
310 ciField *field = CURRENT_ENV->get_field_by_index(loading_klass, index);
311
312 Bytecodes::Code code = (Bytecodes::Code)(((int) byteCode) & 0xFF);
313 Handle field_handle = C1XCompiler::get_RiField(field, loading_klass, cp->pool_holder(), code, THREAD);
314 bool is_constant = field->is_constant();
315 if (is_constant && field->is_static()) {
316 ciConstant constant = field->constant_value();
317 oop constant_object = NULL;
318 switch (constant.basic_type()) {
319 case T_OBJECT:
320 case T_ARRAY:
321 {
322 ciObject* obj = constant.as_object();
323 if (obj->is_null_object()) {
324 constant_object = VMExits::createCiConstantObject(NULL, CHECK_0);
325 } else if (obj->can_be_constant()) {
326 constant_object = VMExits::createCiConstantObject(constant.as_object()->get_oop(), CHECK_0);
327 }
328 }
329 break;
330 case T_DOUBLE:
331 constant_object = VMExits::createCiConstantDouble(constant.as_double(), CHECK_0);
332 break;
333 case T_FLOAT:
334 constant_object = VMExits::createCiConstantFloat(constant.as_float(), CHECK_0);
335 break;
336 case T_LONG:
337 constant_object = VMExits::createCiConstant(CiKind::Long(), constant.as_long(), CHECK_0);
338 break;
339 case T_INT:
340 constant_object = VMExits::createCiConstant(CiKind::Int(), constant.as_int(), CHECK_0);
341 break;
342 case T_SHORT:
343 constant_object = VMExits::createCiConstant(CiKind::Short(), constant.as_int(), CHECK_0);
344 break;
345 case T_CHAR:
346 constant_object = VMExits::createCiConstant(CiKind::Char(), constant.as_int(), CHECK_0);
347 break;
348 case T_BYTE:
349 constant_object = VMExits::createCiConstant(CiKind::Byte(), constant.as_int(), CHECK_0);
350 break;
351 case T_BOOLEAN:
352 constant_object = VMExits::createCiConstant(CiKind::Boolean(), constant.as_int(), CHECK_0);
353 break;
354 default:
355 constant.print();
356 fatal("Unhandled constant");
357 }
358 if (constant_object != NULL) {
359 HotSpotField::set_constant(field_handle, constant_object);
360 }
361 }
362 return JNIHandles::make_local(THREAD, field_handle());
363 }
364
365 // public RiConstantPool RiType_constantPool(HotSpotTypeResolved klass);
366 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiType_1constantPool(JNIEnv *, jobject, jobject klass) {
367 TRACE_C1X_3("VMEntries::RiType_constantPool");
368 VM_ENTRY_MARK;
369
370 assert(JNIHandles::resolve(klass) != NULL, "");
371 constantPoolOop constantPool = ((instanceKlass*)java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass))->klass_part())->constants();
372 return JNIHandles::make_local(VMExits::createRiConstantPool(VmIds::add<constantPoolOop>(constantPool), THREAD));
373 }
374
375 // public RiMethod RiType_resolveMethodImpl(HotSpotTypeResolved klass, String name, String signature);
376 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiType_3resolveMethodImpl(JNIEnv *, jobject, jobject resolved_type, jstring name, jstring signature) {
377 TRACE_C1X_3("VMEntries::RiType_resolveMethodImpl");
378 VM_ENTRY_MARK;
379
380 assert(JNIHandles::resolve(resolved_type) != NULL, "");
381 klassOop klass = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(resolved_type));
382 Symbol* name_symbol = VmIds::toSymbol(name);
383 Symbol* signature_symbol = VmIds::toSymbol(signature);
384 methodOop method = klass->klass_part()->lookup_method(name_symbol, signature_symbol);
385 if (method == NULL) {
386 if (TraceC1X >= 3) {
387 ResourceMark rm;
388 tty->print_cr("Could not resolve method %s %s on klass %s", name_symbol->as_C_string(), signature_symbol->as_C_string(), klass->klass_part()->name()->as_C_string());
389 }
390 return NULL;
391 }
392 return JNIHandles::make_local(THREAD, VMExits::createRiMethodResolved(VmIds::add<methodOop>(method), Handle(JNIHandles::resolve(name)), THREAD));
393 }
394
395 // public boolean RiType_isSubtypeOf(HotSpotTypeResolved klass, RiType other);
396 JNIEXPORT jboolean JNICALL Java_com_oracle_graal_runtime_VMEntries_RiType_2isSubtypeOf(JNIEnv *, jobject, jobject klass, jobject jother) {
397 TRACE_C1X_3("VMEntries::RiType_isSubtypeOf");
398 oop other = JNIHandles::resolve(jother);
399 assert(other->is_a(HotSpotTypeResolved::klass()), "resolved hotspot type expected");
400 assert(JNIHandles::resolve(klass) != NULL, "");
401 klassOop thisKlass = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass));
402 klassOop otherKlass = java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(other));
403 if (thisKlass->klass_part()->oop_is_instance_slow()) {
404 return instanceKlass::cast(thisKlass)->is_subtype_of(otherKlass);
405 } else if (thisKlass->klass_part()->oop_is_array()) {
406 return arrayKlass::cast(thisKlass)->is_subtype_of(otherKlass);
407 } else {
408 fatal("unexpected class type");
409 return false;
410 }
411 }
412
413 // public RiType RiType_componentType(HotSpotResolvedType klass);
414 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiType_1componentType(JNIEnv *, jobject, jobject klass) {
415 TRACE_C1X_3("VMEntries::RiType_componentType");
416 ciArrayKlass* array_klass;
417 {
418 VM_ENTRY_MARK;
419 assert(JNIHandles::resolve(klass) != NULL, "");
420 array_klass = (ciArrayKlass *) CURRENT_ENV->get_object(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass)));
421 }
422 ciType* element_type = array_klass->element_type();
423
424 VM_ENTRY_MARK;
425 assert(JNIHandles::resolve(klass) != NULL, "");
426 return JNIHandles::make_local(C1XCompiler::get_RiType(element_type, java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass)), THREAD));
427 }
428
429 // public RiType RiType_superType(HotSpotResolvedType klass);
430 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiType_1superType(JNIEnv *, jobject, jobject klass) {
431 TRACE_C1X_3("VMEntries::RiType_superType");
432 VM_ENTRY_MARK;
433 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass)));
434 ciInstanceKlass* k = NULL;
435
436 if (klass_handle->oop_is_array()) {
437 k = (ciInstanceKlass *) CURRENT_ENV->get_object(SystemDictionary::Object_klass());
438 } else {
439 guarantee(klass_handle->oop_is_instance(), "must be instance klass");
440 k = (ciInstanceKlass *) CURRENT_ENV->get_object(klass_handle());
441 k = k->super();
442 }
443
444 if (k != NULL) {
445 return JNIHandles::make_local(C1XCompiler::get_RiType(k, klass_handle, THREAD));
446 } else {
447 return NULL;
448 }
449 }
450
451 // public RiType RiType_uniqueConcreteSubtype(HotSpotResolvedType klass);
452 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiType_1uniqueConcreteSubtype(JNIEnv *, jobject, jobject klass) {
453 TRACE_C1X_3("VMEntries::RiType_uniqueConcreteSubtype");
454 Thread* THREAD = Thread::current();
455 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass)));
456 ciInstanceKlass* k = NULL;
457 {
458 VM_ENTRY_MARK;
459 k = (ciInstanceKlass *) CURRENT_ENV->get_object(klass_handle());
460 }
461
462 if (k->is_abstract()) {
463 ciInstanceKlass* sub = k->unique_concrete_subklass();
464 if (sub != NULL && sub->is_leaf_type()) {
465 VM_ENTRY_MARK;
466 return JNIHandles::make_local(C1XCompiler::get_RiType(sub, klass_handle, THREAD));
467 }
468 } else if (k->is_leaf_type()) {
469 assert(!k->is_interface(), "");
470 return klass;
471 }
472
473 return NULL;
474 }
475
476 // public RiType RiType_arrayOf(HotSpotTypeResolved klass);
477 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiType_1arrayOf(JNIEnv *, jobject, jobject klass) {
478 TRACE_C1X_3("VMEntries::RiType_arrayOf");
479 VM_ENTRY_MARK;
480
481 KlassHandle klass_handle(java_lang_Class::as_klassOop(HotSpotTypeResolved::javaMirror(klass)));
482 KlassHandle array = klass_handle->array_klass(THREAD);
483 Handle name = VmIds::toString<Handle>(array->name(), CHECK_NULL);
484 return JNIHandles::make_local(THREAD, C1XCompiler::createHotSpotTypeResolved(array, name, THREAD));
485 }
486
487 // public RiType getPrimitiveArrayType(CiKind kind);
488 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_getPrimitiveArrayType(JNIEnv *env, jobject, jobject kind) {
489 TRACE_C1X_3("VMEntries::VMEntries_getPrimitiveArrayType");
490 VM_ENTRY_MARK;
491 BasicType type = C1XCompiler::kindToBasicType(CiKind::typeChar(kind));
492 assert(type != T_OBJECT, "primitive type expecteds");
493 ciKlass* klass = ciTypeArrayKlass::make(type);
494 return JNIHandles::make_local(THREAD, C1XCompiler::get_RiType(klass, KlassHandle(), THREAD));
495 }
496
497 // public RiType getType(Class<?> javaClass);
498 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_getType(JNIEnv *env, jobject, jobject javaClass) {
499 TRACE_C1X_3("VMEntries::VMEntries_getType");
500 VM_ENTRY_MARK;
501 oop javaClassOop = JNIHandles::resolve(javaClass);
502 if (javaClassOop == NULL) {
503 fatal("argument to VMEntries.getType must not be NULL");
504 return NULL;
505 } else if (java_lang_Class::is_primitive(javaClassOop)) {
506 BasicType basicType = java_lang_Class::primitive_type(javaClassOop);
507 return JNIHandles::make_local(THREAD, VMExits::createRiTypePrimitive((int) basicType, THREAD));
508 } else {
509 KlassHandle klass = java_lang_Class::as_klassOop(javaClassOop);
510 Handle name = java_lang_String::create_from_symbol(klass->name(), CHECK_NULL);
511
512 oop type = C1XCompiler::createHotSpotTypeResolved(klass, name, CHECK_NULL);
513 return JNIHandles::make_local(THREAD, type);
514 }
515 }
516
517
518 // helpers used to set fields in the HotSpotVMConfig object
519 jfieldID getFieldID(JNIEnv* env, jobject obj, const char* name, const char* sig) {
520 jfieldID id = env->GetFieldID(env->GetObjectClass(obj), name, sig);
521 if (id == NULL) {
522 TRACE_C1X_1("field not found: %s (%s)", name, sig);
523 fatal("field not found");
524 }
525 return id;
526 }
527
528 void set_boolean(JNIEnv* env, jobject obj, const char* name, bool value) { env->SetBooleanField(obj, getFieldID(env, obj, name, "Z"), value); }
529 void set_int(JNIEnv* env, jobject obj, const char* name, int value) { env->SetIntField(obj, getFieldID(env, obj, name, "I"), value); }
530 void set_long(JNIEnv* env, jobject obj, const char* name, jlong value) { env->SetLongField(obj, getFieldID(env, obj, name, "J"), value); }
531 void set_object(JNIEnv* env, jobject obj, const char* name, jobject value) { env->SetObjectField(obj, getFieldID(env, obj, name, "Ljava/lang/Object;"), value); }
532 void set_int_array(JNIEnv* env, jobject obj, const char* name, jarray value) { env->SetObjectField(obj, getFieldID(env, obj, name, "[I"), value); }
533
534 jboolean get_boolean(JNIEnv* env, jobject obj, const char* name) { return env->GetBooleanField(obj, getFieldID(env, obj, name, "Z")); }
535 jint get_int(JNIEnv* env, jobject obj, const char* name) { return env->GetIntField(obj, getFieldID(env, obj, name, "I")); }
536 jlong get_long(JNIEnv* env, jobject obj, const char* name) { return env->GetLongField(obj, getFieldID(env, obj, name, "J")); }
537 jobject get_object(JNIEnv* env, jobject obj, const char* name) { return env->GetObjectField(obj, getFieldID(env, obj, name, "Ljava/lang/Object;")); }
538 jobject get_object(JNIEnv* env, jobject obj, const char* name, const char* sig) { return env->GetObjectField(obj, getFieldID(env, obj, name, sig)); }
539
540
541 BasicType basicTypes[] = { T_BOOLEAN, T_BYTE, T_SHORT, T_CHAR, T_INT, T_FLOAT, T_LONG, T_DOUBLE, T_OBJECT };
542 int basicTypeCount = sizeof(basicTypes) / sizeof(BasicType);
543
544 // public HotSpotVMConfig getConfiguration();
545 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_getConfiguration(JNIEnv *env, jobject) {
546 jclass klass = env->FindClass("com/oracle/max/graal/runtime/HotSpotVMConfig");
547 assert(klass != NULL, "HotSpot vm config class not found");
548 jobject config = env->AllocObject(klass);
549 #ifdef _WIN64
550 set_boolean(env, config, "windowsOs", true);
551 #else
552 set_boolean(env, config, "windowsOs", false);
553 #endif
554 set_boolean(env, config, "verifyPointers", VerifyOops);
555 set_boolean(env, config, "useFastLocking", UseFastLocking);
556 set_boolean(env, config, "useFastNewObjectArray", UseFastNewObjectArray);
557 set_boolean(env, config, "useFastNewTypeArray", UseFastNewTypeArray);
558 set_int(env, config, "codeEntryAlignment", CodeEntryAlignment);
559 set_int(env, config, "vmPageSize", os::vm_page_size());
560 set_int(env, config, "stackShadowPages", StackShadowPages);
561 set_int(env, config, "hubOffset", oopDesc::klass_offset_in_bytes());
562 set_int(env, config, "arrayLengthOffset", arrayOopDesc::length_offset_in_bytes());
563 set_int(env, config, "klassStateOffset", instanceKlass::init_state_offset_in_bytes() + sizeof(oopDesc));
564 set_int(env, config, "klassStateFullyInitialized", (int)instanceKlass::fully_initialized);
565 set_int(env, config, "threadTlabTopOffset", in_bytes(JavaThread::tlab_top_offset()));
566 set_int(env, config, "threadTlabEndOffset", in_bytes(JavaThread::tlab_end_offset()));
567 set_int(env, config, "threadObjectOffset", in_bytes(JavaThread::threadObj_offset()));
568 set_int(env, config, "instanceHeaderPrototypeOffset", Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes());
569 set_int(env, config, "threadExceptionOopOffset", in_bytes(JavaThread::exception_oop_offset()));
570 set_int(env, config, "threadExceptionPcOffset", in_bytes(JavaThread::exception_pc_offset()));
571 set_int(env, config, "threadMultiNewArrayStorage", in_bytes(JavaThread::c1x_multinewarray_storage_offset()));
572 set_int(env, config, "classMirrorOffset", klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes());
573
574 set_long(env, config, "debugStub", VmIds::addStub((address)warning));
575 set_long(env, config, "instanceofStub", VmIds::addStub(Runtime1::entry_for(Runtime1::slow_subtype_check_id)));
576 set_long(env, config, "verifyPointerStub", VmIds::addStub(Runtime1::entry_for(Runtime1::c1x_verify_pointer_id)));
577 set_long(env, config, "newInstanceStub", VmIds::addStub(Runtime1::entry_for(Runtime1::fast_new_instance_init_check_id)));
578 set_long(env, config, "unresolvedNewInstanceStub", VmIds::addStub(Runtime1::entry_for(Runtime1::new_instance_id)));
579 set_long(env, config, "newTypeArrayStub", VmIds::addStub(Runtime1::entry_for(Runtime1::new_type_array_id)));
580 set_long(env, config, "newObjectArrayStub", VmIds::addStub(Runtime1::entry_for(Runtime1::new_object_array_id)));
581 set_long(env, config, "newMultiArrayStub", VmIds::addStub(Runtime1::entry_for(Runtime1::new_multi_array_id)));
582 set_long(env, config, "loadKlassStub", VmIds::addStub(Runtime1::entry_for(Runtime1::load_klass_patching_id)));
583 set_long(env, config, "accessFieldStub", VmIds::addStub(Runtime1::entry_for(Runtime1::access_field_patching_id)));
584 set_long(env, config, "resolveStaticCallStub", VmIds::addStub(SharedRuntime::get_resolve_static_call_stub()));
585 set_long(env, config, "inlineCacheMissStub", VmIds::addStub(SharedRuntime::get_ic_miss_stub()));
586 set_long(env, config, "unwindExceptionStub", VmIds::addStub(Runtime1::entry_for(Runtime1::c1x_unwind_exception_call_id)));
587 set_long(env, config, "handleExceptionStub", VmIds::addStub(Runtime1::entry_for(Runtime1::handle_exception_nofpu_id)));
588 set_long(env, config, "handleDeoptStub", VmIds::addStub(SharedRuntime::deopt_blob()->unpack()));
589 set_long(env, config, "monitorEnterStub", VmIds::addStub(Runtime1::entry_for(Runtime1::monitorenter_id)));
590 set_long(env, config, "monitorExitStub", VmIds::addStub(Runtime1::entry_for(Runtime1::monitorexit_id)));
591 set_long(env, config, "fastMonitorEnterStub", VmIds::addStub(Runtime1::entry_for(Runtime1::c1x_monitorenter_id)));
592 set_long(env, config, "fastMonitorExitStub", VmIds::addStub(Runtime1::entry_for(Runtime1::c1x_monitorexit_id)));
593 set_long(env, config, "safepointPollingAddress", (jlong)(os::get_polling_page() + (SafepointPollOffset % os::vm_page_size())));
594
595 BarrierSet* bs = Universe::heap()->barrier_set();
596 switch (bs->kind()) {
597 case BarrierSet::CardTableModRef:
598 case BarrierSet::CardTableExtension: {
599 jlong base = (jlong)((CardTableModRefBS*)bs)->byte_map_base;
600 assert(base != 0, "unexpected byte_map_base");
601 set_long(env, config, "cardtableStartAddress", base);
602 set_int(env, config, "cardtableShift", CardTableModRefBS::card_shift);
603 break;
604 }
605 case BarrierSet::ModRef:
606 case BarrierSet::Other:
607 set_long(env, config, "cardtableStartAddress", 0);
608 set_int(env, config, "cardtableShift", 0);
609 // No post barriers
610 break;
611 #ifndef SERIALGC
612 case BarrierSet::G1SATBCT:
613 case BarrierSet::G1SATBCTLogging:
614 #endif // SERIALGC
615 default:
616 ShouldNotReachHere();
617 }
618
619 jintArray arrayOffsets = env->NewIntArray(basicTypeCount);
620 for (int i=0; i<basicTypeCount; i++) {
621 jint offset = arrayOopDesc::base_offset_in_bytes(basicTypes[i]);
622 env->SetIntArrayRegion(arrayOffsets, i, 1, &offset);
623 }
624 set_int_array(env, config, "arrayOffsets", arrayOffsets);
625 set_int(env, config, "arrayClassElementOffset", objArrayKlass::element_klass_offset_in_bytes() + sizeof(oopDesc));
626 return config;
627 }
628
629 // public void installMethod(HotSpotTargetMethod targetMethod);
630 JNIEXPORT void JNICALL Java_com_oracle_graal_runtime_VMEntries_installMethod(JNIEnv *jniEnv, jobject, jobject targetMethod) {
631 VM_ENTRY_MARK;
632 CodeInstaller installer(JNIHandles::resolve(targetMethod));
633 }
634
635 // public HotSpotProxy installStub(HotSpotTargetMethod targetMethod, String name);
636 JNIEXPORT jlong JNICALL Java_com_oracle_graal_runtime_VMEntries_installStub(JNIEnv *jniEnv, jobject, jobject targetMethod) {
637 VM_ENTRY_MARK;
638 jlong id;
639 CodeInstaller installer(JNIHandles::resolve(targetMethod), id);
640 return id;
641 }
642
643 // public void recordBailout(String reason);
644 JNIEXPORT void JNICALL Java_com_oracle_graal_runtime_VMEntries_recordBailout(JNIEnv *jniEnv, jobject, jobject message) {
645 if (C1XBailoutIsFatal) {
646 Handle msg = JNIHandles::resolve(message);
647 if (!msg.is_null()) {
648 java_lang_String::print(msg, tty);
649 }
650 vm_abort(false);
651 }
652 }
653
654
655
656
657 #define CC (char*) /*cast a literal from (const char*)*/
658 #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &f)
659
660 #define PROXY "J"
661 #define TYPE "Lcom/sun/cri/ri/RiType;"
662 #define RESOLVED_TYPE "Lcom/oracle/max/graal/runtime/HotSpotTypeResolved;"
663 #define METHOD "Lcom/sun/cri/ri/RiMethod;"
664 #define SIGNATURE "Lcom/sun/cri/ri/RiSignature;"
665 #define FIELD "Lcom/sun/cri/ri/RiField;"
666 #define CONSTANT_POOL "Lcom/sun/cri/ri/RiConstantPool;"
667 #define EXCEPTION_HANDLERS "[Lcom/sun/cri/ri/RiExceptionHandler;"
668 #define TARGET_METHOD "Lcom/oracle/max/graal/runtime/HotSpotTargetMethod;"
669 #define CONFIG "Lcom/oracle/max/graal/runtime/HotSpotVMConfig;"
670 #define HS_METHOD "Lcom/oracle/max/graal/runtime/HotSpotMethod;"
671 #define CI_CONSTANT "Lcom/sun/cri/ci/CiConstant;"
672 #define CI_KIND "Lcom/sun/cri/ci/CiKind;"
673 #define STRING "Ljava/lang/String;"
674 #define OBJECT "Ljava/lang/Object;"
675 #define CLASS "Ljava/lang/Class;"
676
677 JNINativeMethod VMEntries_methods[] = {
678 {CC"RiMethod_code", CC"("PROXY")[B", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1code)},
679 {CC"RiMethod_maxStackSize", CC"("PROXY")I", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1maxStackSize)},
680 {CC"RiMethod_maxLocals", CC"("PROXY")I", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1maxLocals)},
681 {CC"RiMethod_holder", CC"("PROXY")"TYPE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1holder)},
682 {CC"RiMethod_signature", CC"("PROXY")"STRING, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1signature)},
683 {CC"RiMethod_accessFlags", CC"("PROXY")I", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1accessFlags)},
684 {CC"RiMethod_exceptionHandlers", CC"("PROXY")"EXCEPTION_HANDLERS, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1exceptionHandlers)},
685 {CC"RiMethod_hasBalancedMonitors", CC"("PROXY")Z", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1hasBalancedMonitors)},
686 {CC"RiMethod_uniqueConcreteMethod", CC"("PROXY")"METHOD, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1uniqueConcreteMethod)},
687 {CC"RiSignature_lookupType", CC"("STRING RESOLVED_TYPE")"TYPE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiSignature_1lookupType)},
688 {CC"RiConstantPool_lookupConstant", CC"("PROXY"I)"OBJECT, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupConstant)},
689 {CC"RiConstantPool_lookupMethod", CC"("PROXY"IB)"METHOD, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupMethod)},
690 {CC"RiConstantPool_lookupSignature", CC"("PROXY"I)"SIGNATURE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupSignature)},
691 {CC"RiConstantPool_lookupType", CC"("PROXY"I)"TYPE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupType)},
692 {CC"RiConstantPool_lookupField", CC"("PROXY"IB)"FIELD, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiConstantPool_1lookupField)},
693 {CC"RiType_constantPool", CC"("RESOLVED_TYPE")"CONSTANT_POOL, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiType_1constantPool)},
694 {CC"RiType_resolveMethodImpl", CC"("RESOLVED_TYPE STRING STRING")"METHOD, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiType_3resolveMethodImpl)},
695 {CC"RiType_isSubtypeOf", CC"("RESOLVED_TYPE TYPE")Z", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiType_2isSubtypeOf)},
696 {CC"RiType_componentType", CC"("RESOLVED_TYPE")"TYPE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiType_1componentType)},
697 {CC"RiType_uniqueConcreteSubtype", CC"("RESOLVED_TYPE")"TYPE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiType_1uniqueConcreteSubtype)},
698 {CC"RiType_superType", CC"("RESOLVED_TYPE")"TYPE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiType_1superType)},
699 {CC"RiType_arrayOf", CC"("RESOLVED_TYPE")"TYPE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiType_1arrayOf)},
700 {CC"getPrimitiveArrayType", CC"("CI_KIND")"TYPE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_getPrimitiveArrayType)},
701 {CC"getType", CC"("CLASS")"TYPE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_getType)},
702 {CC"getConfiguration", CC"()"CONFIG, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_getConfiguration)},
703 {CC"installMethod", CC"("TARGET_METHOD")V", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_installMethod)},
704 {CC"installStub", CC"("TARGET_METHOD")"PROXY, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_installStub)},
705 {CC"recordBailout", CC"("STRING")V", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_recordBailout)}
706 };
707
708 int VMEntries_methods_count() {
709 return sizeof(VMEntries_methods) / sizeof(JNINativeMethod);
710 }