1 /*
2 * Copyright (c) 1999, 2015, 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 *
265 return;
266 }
267
268 assert(canonical_holder == field_desc.field_holder(), "just checking");
269 }
270
271 // ------------------------------------------------------------------
272 // Get a field by index from a klass's constant pool.
273 void JVMCIEnv::get_field_by_index(instanceKlassHandle accessor, fieldDescriptor& fd, int index) {
274 ResourceMark rm;
275 return get_field_by_index_impl(accessor, fd, index);
276 }
277
278 // ------------------------------------------------------------------
279 // Perform an appropriate method lookup based on accessor, holder,
280 // name, signature, and bytecode.
281 methodHandle JVMCIEnv::lookup_method(instanceKlassHandle h_accessor,
282 instanceKlassHandle h_holder,
283 Symbol* name,
284 Symbol* sig,
285 Bytecodes::Code bc) {
286 JVMCI_EXCEPTION_CONTEXT;
287 LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL));
288 methodHandle dest_method;
289 LinkInfo link_info(h_holder, name, sig, h_accessor, /*check_access*/true);
290 switch (bc) {
291 case Bytecodes::_invokestatic:
292 dest_method =
293 LinkResolver::resolve_static_call_or_null(link_info);
294 break;
295 case Bytecodes::_invokespecial:
296 dest_method =
297 LinkResolver::resolve_special_call_or_null(link_info);
298 break;
299 case Bytecodes::_invokeinterface:
300 dest_method =
301 LinkResolver::linktime_resolve_interface_method_or_null(link_info);
302 break;
303 case Bytecodes::_invokevirtual:
304 dest_method =
305 LinkResolver::linktime_resolve_virtual_method_or_null(link_info);
306 break;
307 default: ShouldNotReachHere();
308 }
309
342 // Short-circuit lookups for JSR 292-related call sites.
343 // That is, do not rely only on name-based lookups, because they may fail
344 // if the names are not resolvable in the boot class loader (7056328).
345 switch (bc) {
346 case Bytecodes::_invokevirtual:
347 case Bytecodes::_invokeinterface:
348 case Bytecodes::_invokespecial:
349 case Bytecodes::_invokestatic:
350 {
351 Method* m = ConstantPool::method_at_if_loaded(cpool, index);
352 if (m != NULL) {
353 return m;
354 }
355 }
356 break;
357 }
358 }
359
360 if (holder_is_accessible) { // Our declared holder is loaded.
361 instanceKlassHandle lookup = get_instance_klass_for_declared_method_holder(holder);
362 methodHandle m = lookup_method(accessor, lookup, name_sym, sig_sym, bc);
363 if (!m.is_null() &&
364 (bc == Bytecodes::_invokestatic
365 ? InstanceKlass::cast(m->method_holder())->is_not_initialized()
366 : !InstanceKlass::cast(m->method_holder())->is_loaded())) {
367 m = NULL;
368 }
369 if (!m.is_null()) {
370 // We found the method.
371 return m;
372 }
373 }
374
375 // Either the declared holder was not loaded, or the method could
376 // not be found.
377
378 return NULL;
379 }
380
381 // ------------------------------------------------------------------
382 instanceKlassHandle JVMCIEnv::get_instance_klass_for_declared_method_holder(KlassHandle method_holder) {
|
1 /*
2 * Copyright (c) 1999, 2016, 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 *
265 return;
266 }
267
268 assert(canonical_holder == field_desc.field_holder(), "just checking");
269 }
270
271 // ------------------------------------------------------------------
272 // Get a field by index from a klass's constant pool.
273 void JVMCIEnv::get_field_by_index(instanceKlassHandle accessor, fieldDescriptor& fd, int index) {
274 ResourceMark rm;
275 return get_field_by_index_impl(accessor, fd, index);
276 }
277
278 // ------------------------------------------------------------------
279 // Perform an appropriate method lookup based on accessor, holder,
280 // name, signature, and bytecode.
281 methodHandle JVMCIEnv::lookup_method(instanceKlassHandle h_accessor,
282 instanceKlassHandle h_holder,
283 Symbol* name,
284 Symbol* sig,
285 Bytecodes::Code bc,
286 constantTag tag) {
287 JVMCI_EXCEPTION_CONTEXT;
288 LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL));
289 methodHandle dest_method;
290 LinkInfo link_info(h_holder, name, sig, h_accessor, LinkInfo::needs_access_check, tag);
291 switch (bc) {
292 case Bytecodes::_invokestatic:
293 dest_method =
294 LinkResolver::resolve_static_call_or_null(link_info);
295 break;
296 case Bytecodes::_invokespecial:
297 dest_method =
298 LinkResolver::resolve_special_call_or_null(link_info);
299 break;
300 case Bytecodes::_invokeinterface:
301 dest_method =
302 LinkResolver::linktime_resolve_interface_method_or_null(link_info);
303 break;
304 case Bytecodes::_invokevirtual:
305 dest_method =
306 LinkResolver::linktime_resolve_virtual_method_or_null(link_info);
307 break;
308 default: ShouldNotReachHere();
309 }
310
343 // Short-circuit lookups for JSR 292-related call sites.
344 // That is, do not rely only on name-based lookups, because they may fail
345 // if the names are not resolvable in the boot class loader (7056328).
346 switch (bc) {
347 case Bytecodes::_invokevirtual:
348 case Bytecodes::_invokeinterface:
349 case Bytecodes::_invokespecial:
350 case Bytecodes::_invokestatic:
351 {
352 Method* m = ConstantPool::method_at_if_loaded(cpool, index);
353 if (m != NULL) {
354 return m;
355 }
356 }
357 break;
358 }
359 }
360
361 if (holder_is_accessible) { // Our declared holder is loaded.
362 instanceKlassHandle lookup = get_instance_klass_for_declared_method_holder(holder);
363 constantTag tag = cpool->tag_ref_at(index);
364 methodHandle m = lookup_method(accessor, lookup, name_sym, sig_sym, bc, tag);
365 if (!m.is_null() &&
366 (bc == Bytecodes::_invokestatic
367 ? InstanceKlass::cast(m->method_holder())->is_not_initialized()
368 : !InstanceKlass::cast(m->method_holder())->is_loaded())) {
369 m = NULL;
370 }
371 if (!m.is_null()) {
372 // We found the method.
373 return m;
374 }
375 }
376
377 // Either the declared holder was not loaded, or the method could
378 // not be found.
379
380 return NULL;
381 }
382
383 // ------------------------------------------------------------------
384 instanceKlassHandle JVMCIEnv::get_instance_klass_for_declared_method_holder(KlassHandle method_holder) {
|