< prev index next >

src/hotspot/share/classfile/verificationType.cpp

Print this page


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


  94     // We need check the class hierarchy to check assignability
  95     if (name() == vmSymbols::java_lang_Object()) {
  96       // any object or array is assignable to java.lang.Object
  97       return true;
  98     }
  99 
 100     if (DumpSharedSpaces && SystemDictionaryShared::add_verification_constraint(klass,
 101               name(), from.name(), from_field_is_protected, from.is_array(),
 102               from.is_object())) {
 103       // If add_verification_constraint() returns true, the resolution/check should be
 104       // delayed until runtime.
 105       return true;
 106     }
 107 
 108     return resolve_and_check_assignability(klass, name(), from.name(),
 109           from_field_is_protected, from.is_array(), from.is_object(), THREAD);
 110   } else if (is_array() && from.is_array()) {
 111     VerificationType comp_this = get_component(context, CHECK_false);
 112     VerificationType comp_from = from.get_component(context, CHECK_false);
 113 



 114     if (comp_from.is_valuetype() && !comp_this.is_null() && comp_this.is_reference()) {
 115       // An array of value types is not assignable to an array of java.lang.Objects.
 116       if (comp_this.name() == vmSymbols::java_lang_Object()) {
 117         return false;
 118       }
 119 
 120       // Need to load 'comp_this' to see if it is an interface.
 121       InstanceKlass* klass = context->current_class();
 122       {
 123         HandleMark hm(THREAD);
 124         Klass* comp_this_class = SystemDictionary::resolve_or_fail(
 125             comp_this.name(), Handle(THREAD, klass->class_loader()),
 126             Handle(THREAD, klass->protection_domain()), true, CHECK_false);
 127         klass->class_loader_data()->record_dependency(comp_this_class);
 128         if (log_is_enabled(Debug, class, resolve)) {
 129           Verifier::trace_class_resolution(comp_this_class, klass);
 130         }
 131         // An array of value types is not assignable to an array of interface types.
 132         if (comp_this_class->is_interface()) {
 133           return false;


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


  94     // We need check the class hierarchy to check assignability
  95     if (name() == vmSymbols::java_lang_Object()) {
  96       // any object or array is assignable to java.lang.Object
  97       return true;
  98     }
  99 
 100     if (DumpSharedSpaces && SystemDictionaryShared::add_verification_constraint(klass,
 101               name(), from.name(), from_field_is_protected, from.is_array(),
 102               from.is_object())) {
 103       // If add_verification_constraint() returns true, the resolution/check should be
 104       // delayed until runtime.
 105       return true;
 106     }
 107 
 108     return resolve_and_check_assignability(klass, name(), from.name(),
 109           from_field_is_protected, from.is_array(), from.is_object(), THREAD);
 110   } else if (is_array() && from.is_array()) {
 111     VerificationType comp_this = get_component(context, CHECK_false);
 112     VerificationType comp_from = from.get_component(context, CHECK_false);
 113 
 114     // This code implements non-covariance between value type arrays and both
 115     // arrays of objects and arrays of interface types.  If covariance is
 116     // supported for value type arrays then this code should be removed.
 117     if (comp_from.is_valuetype() && !comp_this.is_null() && comp_this.is_reference()) {
 118       // An array of value types is not assignable to an array of java.lang.Objects.
 119       if (comp_this.name() == vmSymbols::java_lang_Object()) {
 120         return false;
 121       }
 122 
 123       // Need to load 'comp_this' to see if it is an interface.
 124       InstanceKlass* klass = context->current_class();
 125       {
 126         HandleMark hm(THREAD);
 127         Klass* comp_this_class = SystemDictionary::resolve_or_fail(
 128             comp_this.name(), Handle(THREAD, klass->class_loader()),
 129             Handle(THREAD, klass->protection_domain()), true, CHECK_false);
 130         klass->class_loader_data()->record_dependency(comp_this_class);
 131         if (log_is_enabled(Debug, class, resolve)) {
 132           Verifier::trace_class_resolution(comp_this_class, klass);
 133         }
 134         // An array of value types is not assignable to an array of interface types.
 135         if (comp_this_class->is_interface()) {
 136           return false;


< prev index next >