hotspot/src/share/vm/classfile/verificationType.cpp
author mockner
Fri, 29 Apr 2016 22:40:51 -0400
changeset 38151 fffedc5e5cf8
parent 37078 dc9ee85e80d3
child 39713 29ece76096cb
permissions -rw-r--r--
8154110: Update class* and safepoint* logging subsystems Summary: Refactored logging tags in class and safepoint subsystems. Reviewed-by: coleenp, rehn, hseigel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
30616
fde3a4fee412 8076318: split verifier needs to add TraceClassResolution
hseigel
parents: 27022
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6473
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6473
diff changeset
    26
#include "classfile/symbolTable.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6473
diff changeset
    27
#include "classfile/verificationType.hpp"
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    28
#include "classfile/verifier.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
VerificationType VerificationType::from_tag(u1 tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  switch (tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
    case ITEM_Top:     return bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
    case ITEM_Integer: return integer_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
    case ITEM_Float:   return float_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
    case ITEM_Double:  return double_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    case ITEM_Long:    return long_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    case ITEM_Null:    return null_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
      return bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
bool VerificationType::is_reference_assignable_from(
27022
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 13728
diff changeset
    45
    const VerificationType& from, ClassVerifier* context,
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 13728
diff changeset
    46
    bool from_field_is_protected, TRAPS) const {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    47
  instanceKlassHandle klass = context->current_class();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  if (from.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    // null is assignable to any reference
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  } else if (is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  } else if (name() == from.name()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  } else if (is_object()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    // We need check the class hierarchy to check assignability
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    if (name() == vmSymbols::java_lang_Object()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
      // any object or array is assignable to java.lang.Object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13476
diff changeset
    61
    Klass* obj = SystemDictionary::resolve_or_fail(
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    62
        name(), Handle(THREAD, klass->class_loader()),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    63
        Handle(THREAD, klass->protection_domain()), true, CHECK_false);
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37078
diff changeset
    64
    if (log_is_enabled(Debug, class, resolve)) {
30616
fde3a4fee412 8076318: split verifier needs to add TraceClassResolution
hseigel
parents: 27022
diff changeset
    65
      Verifier::trace_class_resolution(obj, klass());
fde3a4fee412 8076318: split verifier needs to add TraceClassResolution
hseigel
parents: 27022
diff changeset
    66
    }
fde3a4fee412 8076318: split verifier needs to add TraceClassResolution
hseigel
parents: 27022
diff changeset
    67
6473
04e6d80f38b1 6975210: java.lang.VerifyError in some of JCK tests
kamg
parents: 6172
diff changeset
    68
    KlassHandle this_class(THREAD, obj);
04e6d80f38b1 6975210: java.lang.VerifyError in some of JCK tests
kamg
parents: 6172
diff changeset
    69
27022
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 13728
diff changeset
    70
    if (this_class->is_interface() && (!from_field_is_protected ||
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 13728
diff changeset
    71
        from.name() != vmSymbols::java_lang_Object())) {
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 13728
diff changeset
    72
      // If we are not trying to access a protected field or method in
32819
a815f78586d2 8132904: Type checking verifier fails to reject assignment from array to an interface
hseigel
parents: 31966
diff changeset
    73
      // java.lang.Object then, for arrays, we only allow assignability
a815f78586d2 8132904: Type checking verifier fails to reject assignment from array to an interface
hseigel
parents: 31966
diff changeset
    74
      // to interfaces java.lang.Cloneable and java.io.Serializable.
a815f78586d2 8132904: Type checking verifier fails to reject assignment from array to an interface
hseigel
parents: 31966
diff changeset
    75
      // Otherwise, we treat interfaces as java.lang.Object.
a815f78586d2 8132904: Type checking verifier fails to reject assignment from array to an interface
hseigel
parents: 31966
diff changeset
    76
      return !from.is_array() ||
a815f78586d2 8132904: Type checking verifier fails to reject assignment from array to an interface
hseigel
parents: 31966
diff changeset
    77
        this_class == SystemDictionary::Cloneable_klass() ||
a815f78586d2 8132904: Type checking verifier fails to reject assignment from array to an interface
hseigel
parents: 31966
diff changeset
    78
        this_class == SystemDictionary::Serializable_klass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    } else if (from.is_object()) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13476
diff changeset
    80
      Klass* from_class = SystemDictionary::resolve_or_fail(
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    81
          from.name(), Handle(THREAD, klass->class_loader()),
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    82
          Handle(THREAD, klass->protection_domain()), true, CHECK_false);
38151
fffedc5e5cf8 8154110: Update class* and safepoint* logging subsystems
mockner
parents: 37078
diff changeset
    83
      if (log_is_enabled(Debug, class, resolve)) {
30616
fde3a4fee412 8076318: split verifier needs to add TraceClassResolution
hseigel
parents: 27022
diff changeset
    84
        Verifier::trace_class_resolution(from_class, klass());
fde3a4fee412 8076318: split verifier needs to add TraceClassResolution
hseigel
parents: 27022
diff changeset
    85
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13476
diff changeset
    86
      return InstanceKlass::cast(from_class)->is_subclass_of(this_class());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  } else if (is_array() && from.is_array()) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    89
    VerificationType comp_this = get_component(context, CHECK_false);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    90
    VerificationType comp_from = from.get_component(context, CHECK_false);
6172
e1d9c632fa3c 6964170: Verifier crashes
apangin
parents: 5547
diff changeset
    91
    if (!comp_this.is_bogus() && !comp_from.is_bogus()) {
31966
aa9c386e1240 8129895: New verifier fails to reject erroneous cast from int[] to other arrays of small integer types
hseigel
parents: 30616
diff changeset
    92
      return comp_this.is_component_assignable_from(comp_from, context,
27022
2db6fe33afc2 8036533: Method for correct defaults
hseigel
parents: 13728
diff changeset
    93
                                          from_field_is_protected, CHECK_false);
6172
e1d9c632fa3c 6964170: Verifier crashes
apangin
parents: 5547
diff changeset
    94
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    99
VerificationType VerificationType::get_component(ClassVerifier *context, TRAPS) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array");
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   101
  Symbol* component;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  switch (name()->byte_at(1)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    case 'Z': return VerificationType(Boolean);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    case 'B': return VerificationType(Byte);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    case 'C': return VerificationType(Char);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    case 'S': return VerificationType(Short);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    case 'I': return VerificationType(Integer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    case 'J': return VerificationType(Long);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    case 'F': return VerificationType(Float);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    case 'D': return VerificationType(Double);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    case '[':
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   112
      component = context->create_temporary_symbol(
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
        name(), 1, name()->utf8_length(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
        CHECK_(VerificationType::bogus_type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      return VerificationType::reference_type(component);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    case 'L':
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   117
      component = context->create_temporary_symbol(
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
        name(), 2, name()->utf8_length() - 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
        CHECK_(VerificationType::bogus_type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      return VerificationType::reference_type(component);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    default:
6172
e1d9c632fa3c 6964170: Verifier crashes
apangin
parents: 5547
diff changeset
   122
      // Met an invalid type signature, e.g. [X
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
void VerificationType::print_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  switch (_u._data) {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   129
    case Bogus:            st->print("top"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   130
    case Category1:        st->print("category1"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   131
    case Category2:        st->print("category2"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   132
    case Category2_2nd:    st->print("category2_2nd"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   133
    case Boolean:          st->print("boolean"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   134
    case Byte:             st->print("byte"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   135
    case Short:            st->print("short"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   136
    case Char:             st->print("char"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   137
    case Integer:          st->print("integer"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   138
    case Float:            st->print("float"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   139
    case Long:             st->print("long"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   140
    case Double:           st->print("double"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   141
    case Long_2nd:         st->print("long_2nd"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   142
    case Double_2nd:       st->print("double_2nd"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   143
    case Null:             st->print("null"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   144
    case ReferenceQuery:   st->print("reference type"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   145
    case Category1Query:   st->print("category1 type"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   146
    case Category2Query:   st->print("category2 type"); break;
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   147
    case Category2_2ndQuery: st->print("category2_2nd type"); break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      if (is_uninitialized_this()) {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   150
        st->print("uninitializedThis");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      } else if (is_uninitialized()) {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   152
        st->print("uninitialized %d", bci());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      } else {
13476
471200fb94fd 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 8921
diff changeset
   154
        name()->print_value_on(st);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
}