From 99a0ee14d6aee1729b9463d73b7a3925ceb89756 Mon Sep 17 00:00:00 2001 From: hseigel Date: Fri, 10 Feb 2017 07:46:07 -0500 Subject: [PATCH] 8174092: Remove array-related access checks from Reflection::verify_class_access() Summary: Change the parameter type to InstanceKlass* and fix the method's callers Reviewed-by: acorn, coleenp, gtriantafill, lfoltan --- hotspot/src/share/vm/ci/ciEnv.cpp | 4 ++-- hotspot/src/share/vm/classfile/classFileParser.cpp | 14 +++++++++----- hotspot/src/share/vm/interpreter/linkResolver.cpp | 8 +++++--- hotspot/src/share/vm/jvmci/jvmciEnv.cpp | 4 ++-- hotspot/src/share/vm/prims/methodHandles.cpp | 4 ++-- hotspot/src/share/vm/runtime/reflection.cpp | 13 +++---------- hotspot/src/share/vm/runtime/reflection.hpp | 6 +++--- 7 files changed, 26 insertions(+), 27 deletions(-) diff --git a/hotspot/src/share/vm/ci/ciEnv.cpp b/hotspot/src/share/vm/ci/ciEnv.cpp index 024909b1cb..fce88ba51c 100644 --- a/hotspot/src/share/vm/ci/ciEnv.cpp +++ b/hotspot/src/share/vm/ci/ciEnv.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -374,7 +374,7 @@ bool ciEnv::check_klass_accessibility(ciKlass* accessing_klass, } if (resolved_klass->is_instance_klass()) { return (Reflection::verify_class_access(accessing_klass->get_Klass(), - resolved_klass, + InstanceKlass::cast(resolved_klass), true) == Reflection::ACCESS_OK); } return true; diff --git a/hotspot/src/share/vm/classfile/classFileParser.cpp b/hotspot/src/share/vm/classfile/classFileParser.cpp index f1eace4eb6..87b593eb69 100644 --- a/hotspot/src/share/vm/classfile/classFileParser.cpp +++ b/hotspot/src/share/vm/classfile/classFileParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -4374,10 +4374,12 @@ static void check_super_class_access(const InstanceKlass* this_klass, TRAPS) { } Reflection::VerifyClassAccessResults vca_result = - Reflection::verify_class_access(this_klass, super, false); + Reflection::verify_class_access(this_klass, InstanceKlass::cast(super), false); if (vca_result != Reflection::ACCESS_OK) { ResourceMark rm(THREAD); - char* msg = Reflection::verify_class_access_msg(this_klass, super, vca_result); + char* msg = Reflection::verify_class_access_msg(this_klass, + InstanceKlass::cast(super), + vca_result); if (msg == NULL) { Exceptions::fthrow( THREAD_AND_LOCATION, @@ -4406,10 +4408,12 @@ static void check_super_interface_access(const InstanceKlass* this_klass, TRAPS) Klass* const k = local_interfaces->at(i); assert (k != NULL && k->is_interface(), "invalid interface"); Reflection::VerifyClassAccessResults vca_result = - Reflection::verify_class_access(this_klass, k, false); + Reflection::verify_class_access(this_klass, InstanceKlass::cast(k), false); if (vca_result != Reflection::ACCESS_OK) { ResourceMark rm(THREAD); - char* msg = Reflection::verify_class_access_msg(this_klass, k, vca_result); + char* msg = Reflection::verify_class_access_msg(this_klass, + InstanceKlass::cast(k), + vca_result); if (msg == NULL) { Exceptions::fthrow( THREAD_AND_LOCATION, diff --git a/hotspot/src/share/vm/interpreter/linkResolver.cpp b/hotspot/src/share/vm/interpreter/linkResolver.cpp index b062f2cc4b..ce452bfe1f 100644 --- a/hotspot/src/share/vm/interpreter/linkResolver.cpp +++ b/hotspot/src/share/vm/interpreter/linkResolver.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -275,10 +275,12 @@ void LinkInfo::print() { void LinkResolver::check_klass_accessability(KlassHandle ref_klass, KlassHandle sel_klass, TRAPS) { Reflection::VerifyClassAccessResults vca_result = - Reflection::verify_class_access(ref_klass(), sel_klass(), true); + Reflection::verify_class_access(ref_klass(), InstanceKlass::cast(sel_klass()), true); if (vca_result != Reflection::ACCESS_OK) { ResourceMark rm(THREAD); - char* msg = Reflection::verify_class_access_msg(ref_klass(), sel_klass(), vca_result); + char* msg = Reflection::verify_class_access_msg(ref_klass(), + InstanceKlass::cast(sel_klass()), + vca_result); if (msg == NULL) { Exceptions::fthrow( THREAD_AND_LOCATION, diff --git a/hotspot/src/share/vm/jvmci/jvmciEnv.cpp b/hotspot/src/share/vm/jvmci/jvmciEnv.cpp index 9c5d98361e..65f69d7c60 100644 --- a/hotspot/src/share/vm/jvmci/jvmciEnv.cpp +++ b/hotspot/src/share/vm/jvmci/jvmciEnv.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -79,7 +79,7 @@ bool JVMCIEnv::check_klass_accessibility(KlassHandle accessing_klass, KlassHandl } if (resolved_klass->is_instance_klass()) { Reflection::VerifyClassAccessResults result = - Reflection::verify_class_access(accessing_klass(), resolved_klass(), true); + Reflection::verify_class_access(accessing_klass(), InstanceKlass::cast(resolved_klass()), true); return result == Reflection::ACCESS_OK; } return true; diff --git a/hotspot/src/share/vm/prims/methodHandles.cpp b/hotspot/src/share/vm/prims/methodHandles.cpp index 717c1fe00a..96ccab1071 100644 --- a/hotspot/src/share/vm/prims/methodHandles.cpp +++ b/hotspot/src/share/vm/prims/methodHandles.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1209,7 +1209,7 @@ JVM_ENTRY(jobject, MHN_resolve_Mem(JNIEnv *env, jobject igcls, jobject mname_jh, // Emulate LinkResolver::check_klass_accessability. Klass* caller = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(caller_jh)); if (Reflection::verify_class_access(caller, - reference_klass, + InstanceKlass::cast(reference_klass), true) != Reflection::ACCESS_OK) { THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), reference_klass->external_name()); } diff --git a/hotspot/src/share/vm/runtime/reflection.cpp b/hotspot/src/share/vm/runtime/reflection.cpp index b2fc101882..13909417ce 100644 --- a/hotspot/src/share/vm/runtime/reflection.cpp +++ b/hotspot/src/share/vm/runtime/reflection.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -477,7 +477,7 @@ static bool can_relax_access_check_for(const Klass* accessor, Note: a loose module is a module that can read all current and future unnamed modules. */ Reflection::VerifyClassAccessResults Reflection::verify_class_access( - const Klass* current_class, const Klass* new_class, bool classloader_only) { + const Klass* current_class, const InstanceKlass* new_class, bool classloader_only) { // Verify that current_class can access new_class. If the classloader_only // flag is set, we automatically allow any accesses in which current_class @@ -504,13 +504,6 @@ Reflection::VerifyClassAccessResults Reflection::verify_class_access( // Find the module entry for current_class, the accessor ModuleEntry* module_from = current_class->module(); // Find the module entry for new_class, the accessee - if (new_class->is_objArray_klass()) { - new_class = ObjArrayKlass::cast(new_class)->bottom_klass(); - } - if (new_class->is_typeArray_klass()) { - // A TypeArray's defining module is java.base, access to the TypeArray is allowed - return ACCESS_OK; - } ModuleEntry* module_to = new_class->module(); // both in same (possibly unnamed) module @@ -563,7 +556,7 @@ Reflection::VerifyClassAccessResults Reflection::verify_class_access( // Return an error message specific to the specified Klass*'s and result. // This function must be called from within a block containing a ResourceMark. char* Reflection::verify_class_access_msg(const Klass* current_class, - const Klass* new_class, + const InstanceKlass* new_class, VerifyClassAccessResults result) { assert(result != ACCESS_OK, "must be failure result"); char * msg = NULL; diff --git a/hotspot/src/share/vm/runtime/reflection.hpp b/hotspot/src/share/vm/runtime/reflection.hpp index 736e21f9f6..75ba5d7782 100644 --- a/hotspot/src/share/vm/runtime/reflection.hpp +++ b/hotspot/src/share/vm/runtime/reflection.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -82,12 +82,12 @@ class Reflection: public AllStatic { // Verification static VerifyClassAccessResults verify_class_access(const Klass* current_class, - const Klass* new_class, + const InstanceKlass* new_class, bool classloader_only); // Return an error message specific to the specified Klass*'s and result. // This function must be called from within a block containing a ResourceMark. static char* verify_class_access_msg(const Klass* current_class, - const Klass* new_class, + const InstanceKlass* new_class, const VerifyClassAccessResults result); static bool verify_field_access(const Klass* current_class, -- GitLab