< prev index next >

src/share/vm/prims/methodHandles.cpp

Print this page


   1 /*
   2  * Copyright (c) 2008, 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  *


1192 
1193 // void resolve(MemberName self, Class<?> caller)
1194 JVM_ENTRY(jobject, MHN_resolve_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jclass caller_jh)) {
1195   if (mname_jh == NULL) { THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "mname is null"); }
1196   Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh));
1197 
1198   // The trusted Java code that calls this method should already have performed
1199   // access checks on behalf of the given caller.  But, we can verify this.
1200   if (VerifyMethodHandles && caller_jh != NULL &&
1201       java_lang_invoke_MemberName::clazz(mname()) != NULL) {
1202     Klass* reference_klass = java_lang_Class::as_Klass(java_lang_invoke_MemberName::clazz(mname()));
1203     if (reference_klass != NULL && reference_klass->is_objArray_klass()) {
1204       reference_klass = ObjArrayKlass::cast(reference_klass)->bottom_klass();
1205     }
1206 
1207     // Reflection::verify_class_access can only handle instance classes.
1208     if (reference_klass != NULL && reference_klass->is_instance_klass()) {
1209       // Emulate LinkResolver::check_klass_accessability.
1210       Klass* caller = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh));
1211       if (Reflection::verify_class_access(caller,
1212                                           reference_klass,
1213                                           true) != Reflection::ACCESS_OK) {
1214         THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), reference_klass->external_name());
1215       }
1216     }
1217   }
1218 
1219   KlassHandle caller(THREAD,
1220                      caller_jh == NULL ? (Klass*) NULL :
1221                      java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh)));
1222   Handle resolved = MethodHandles::resolve_MemberName(mname, caller, CHECK_NULL);
1223 
1224   if (resolved.is_null()) {
1225     int flags = java_lang_invoke_MemberName::flags(mname());
1226     int ref_kind = (flags >> REFERENCE_KIND_SHIFT) & REFERENCE_KIND_MASK;
1227     if (!MethodHandles::ref_kind_is_valid(ref_kind)) {
1228       THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "obsolete MemberName format");
1229     }
1230     if ((flags & ALL_KINDS) == IS_FIELD) {
1231       THROW_MSG_NULL(vmSymbols::java_lang_NoSuchFieldError(), "field resolution failed");
1232     } else if ((flags & ALL_KINDS) == IS_METHOD ||


   1 /*
   2  * Copyright (c) 2008, 2017, 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  *


1192 
1193 // void resolve(MemberName self, Class<?> caller)
1194 JVM_ENTRY(jobject, MHN_resolve_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, jclass caller_jh)) {
1195   if (mname_jh == NULL) { THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "mname is null"); }
1196   Handle mname(THREAD, JNIHandles::resolve_non_null(mname_jh));
1197 
1198   // The trusted Java code that calls this method should already have performed
1199   // access checks on behalf of the given caller.  But, we can verify this.
1200   if (VerifyMethodHandles && caller_jh != NULL &&
1201       java_lang_invoke_MemberName::clazz(mname()) != NULL) {
1202     Klass* reference_klass = java_lang_Class::as_Klass(java_lang_invoke_MemberName::clazz(mname()));
1203     if (reference_klass != NULL && reference_klass->is_objArray_klass()) {
1204       reference_klass = ObjArrayKlass::cast(reference_klass)->bottom_klass();
1205     }
1206 
1207     // Reflection::verify_class_access can only handle instance classes.
1208     if (reference_klass != NULL && reference_klass->is_instance_klass()) {
1209       // Emulate LinkResolver::check_klass_accessability.
1210       Klass* caller = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh));
1211       if (Reflection::verify_class_access(caller,
1212                                           InstanceKlass::cast(reference_klass),
1213                                           true) != Reflection::ACCESS_OK) {
1214         THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), reference_klass->external_name());
1215       }
1216     }
1217   }
1218 
1219   KlassHandle caller(THREAD,
1220                      caller_jh == NULL ? (Klass*) NULL :
1221                      java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh)));
1222   Handle resolved = MethodHandles::resolve_MemberName(mname, caller, CHECK_NULL);
1223 
1224   if (resolved.is_null()) {
1225     int flags = java_lang_invoke_MemberName::flags(mname());
1226     int ref_kind = (flags >> REFERENCE_KIND_SHIFT) & REFERENCE_KIND_MASK;
1227     if (!MethodHandles::ref_kind_is_valid(ref_kind)) {
1228       THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "obsolete MemberName format");
1229     }
1230     if ((flags & ALL_KINDS) == IS_FIELD) {
1231       THROW_MSG_NULL(vmSymbols::java_lang_NoSuchFieldError(), "field resolution failed");
1232     } else if ((flags & ALL_KINDS) == IS_METHOD ||


< prev index next >