hotspot/src/share/vm/classfile/verificationType.cpp
author trims
Thu, 27 May 2010 19:08:38 -0700
changeset 5547 f4b087cbb361
parent 1 489c9b5090e2
child 6172 e1d9c632fa3c
permissions -rw-r--r--
6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
     2
 * Copyright (c) 2003, 2006, 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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_verificationType.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
VerificationType VerificationType::from_tag(u1 tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  switch (tag) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
    case ITEM_Top:     return bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
    case ITEM_Integer: return integer_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
    case ITEM_Float:   return float_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
    case ITEM_Double:  return double_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
    case ITEM_Long:    return long_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
    case ITEM_Null:    return null_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
      return bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
bool VerificationType::is_reference_assignable_from(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    const VerificationType& from, instanceKlassHandle context, TRAPS) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  if (from.is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    // null is assignable to any reference
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  } else if (is_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  } else if (name() == from.name()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  } else if (is_object()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    // We need check the class hierarchy to check assignability
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    if (name() == vmSymbols::java_lang_Object()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
      // any object or array is assignable to java.lang.Object
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    klassOop this_class = SystemDictionary::resolve_or_fail(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
        name_handle(), Handle(THREAD, context->class_loader()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
        Handle(THREAD, context->protection_domain()), true, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    if (this_class->klass_part()->is_interface()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
      // We treat interfaces as java.lang.Object, including
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      // java.lang.Cloneable and java.io.Serializable
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    } else if (from.is_object()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      klassOop from_class = SystemDictionary::resolve_or_fail(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
          from.name_handle(), Handle(THREAD, context->class_loader()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
          Handle(THREAD, context->protection_domain()), true, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
      return instanceKlass::cast(from_class)->is_subclass_of(this_class);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  } else if (is_array() && from.is_array()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    VerificationType comp_this = get_component(CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    VerificationType comp_from = from.get_component(CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    return comp_this.is_assignable_from(comp_from, context, CHECK_false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
VerificationType VerificationType::get_component(TRAPS) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  assert(is_array() && name()->utf8_length() >= 2, "Must be a valid array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  symbolOop component;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  switch (name()->byte_at(1)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    case 'Z': return VerificationType(Boolean);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    case 'B': return VerificationType(Byte);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    case 'C': return VerificationType(Char);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    case 'S': return VerificationType(Short);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    case 'I': return VerificationType(Integer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    case 'J': return VerificationType(Long);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    case 'F': return VerificationType(Float);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    case 'D': return VerificationType(Double);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    case '[':
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      component = SymbolTable::lookup(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
        name(), 1, name()->utf8_length(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
        CHECK_(VerificationType::bogus_type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      return VerificationType::reference_type(component);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    case 'L':
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      component = SymbolTable::lookup(
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
        name(), 2, name()->utf8_length() - 1,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
        CHECK_(VerificationType::bogus_type()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      return VerificationType::reference_type(component);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      return VerificationType::bogus_type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
void VerificationType::print_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  switch (_u._data) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    case Bogus:            st->print(" bogus "); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    case Category1:        st->print(" category1 "); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    case Category2:        st->print(" category2 "); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    case Category2_2nd:    st->print(" category2_2nd "); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    case Boolean:          st->print(" boolean "); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    case Byte:             st->print(" byte "); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    case Short:            st->print(" short "); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    case Char:             st->print(" char "); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    case Integer:          st->print(" integer "); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    case Float:            st->print(" float "); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    case Long:             st->print(" long "); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    case Double:           st->print(" double "); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    case Long_2nd:         st->print(" long_2nd "); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    case Double_2nd:       st->print(" double_2nd "); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    case Null:             st->print(" null "); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
      if (is_uninitialized_this()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
        st->print(" uninitializedThis ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      } else if (is_uninitialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
        st->print(" uninitialized %d ", bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
        st->print(" class %s ", name()->as_klass_external_name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
#endif