hotspot/src/share/vm/runtime/reflection.cpp
changeset 46262 83280d968b96
parent 40923 10fe1c28b9f6
child 46289 1904e7ec236e
equal deleted inserted replaced
46261:75ce8b72e3c9 46262:83280d968b96
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   475  ------------------------------------------------------------------------------------------------
   475  ------------------------------------------------------------------------------------------------
   476 
   476 
   477  Note: a loose module is a module that can read all current and future unnamed modules.
   477  Note: a loose module is a module that can read all current and future unnamed modules.
   478 */
   478 */
   479 Reflection::VerifyClassAccessResults Reflection::verify_class_access(
   479 Reflection::VerifyClassAccessResults Reflection::verify_class_access(
   480   const Klass* current_class, const Klass* new_class, bool classloader_only) {
   480   const Klass* current_class, const InstanceKlass* new_class, bool classloader_only) {
   481 
   481 
   482   // Verify that current_class can access new_class.  If the classloader_only
   482   // Verify that current_class can access new_class.  If the classloader_only
   483   // flag is set, we automatically allow any accesses in which current_class
   483   // flag is set, we automatically allow any accesses in which current_class
   484   // doesn't have a classloader.
   484   // doesn't have a classloader.
   485   if ((current_class == NULL) ||
   485   if ((current_class == NULL) ||
   502     }
   502     }
   503 
   503 
   504     // Find the module entry for current_class, the accessor
   504     // Find the module entry for current_class, the accessor
   505     ModuleEntry* module_from = current_class->module();
   505     ModuleEntry* module_from = current_class->module();
   506     // Find the module entry for new_class, the accessee
   506     // Find the module entry for new_class, the accessee
   507     if (new_class->is_objArray_klass()) {
       
   508       new_class = ObjArrayKlass::cast(new_class)->bottom_klass();
       
   509     }
       
   510     if (new_class->is_typeArray_klass()) {
       
   511       // A TypeArray's defining module is java.base, access to the TypeArray is allowed
       
   512       return ACCESS_OK;
       
   513     }
       
   514     ModuleEntry* module_to = new_class->module();
   507     ModuleEntry* module_to = new_class->module();
   515 
   508 
   516     // both in same (possibly unnamed) module
   509     // both in same (possibly unnamed) module
   517     if (module_from == module_to) {
   510     if (module_from == module_to) {
   518       return ACCESS_OK;
   511       return ACCESS_OK;
   561 }
   554 }
   562 
   555 
   563 // Return an error message specific to the specified Klass*'s and result.
   556 // Return an error message specific to the specified Klass*'s and result.
   564 // This function must be called from within a block containing a ResourceMark.
   557 // This function must be called from within a block containing a ResourceMark.
   565 char* Reflection::verify_class_access_msg(const Klass* current_class,
   558 char* Reflection::verify_class_access_msg(const Klass* current_class,
   566                                           const Klass* new_class,
   559                                           const InstanceKlass* new_class,
   567                                           VerifyClassAccessResults result) {
   560                                           VerifyClassAccessResults result) {
   568   assert(result != ACCESS_OK, "must be failure result");
   561   assert(result != ACCESS_OK, "must be failure result");
   569   char * msg = NULL;
   562   char * msg = NULL;
   570   if (result != OTHER_PROBLEM && new_class != NULL && current_class != NULL) {
   563   if (result != OTHER_PROBLEM && new_class != NULL && current_class != NULL) {
   571     // Find the module entry for current_class, the accessor
   564     // Find the module entry for current_class, the accessor