hotspot/src/share/vm/oops/klass.cpp
author brutisso
Mon, 16 Apr 2012 08:57:18 +0200
changeset 12379 2cf45b79ce3a
parent 12236 51d6463cfd9d
child 13728 882756847a04
permissions -rw-r--r--
4988100: oop_verify_old_oop appears to be dead Summary: removed oop_verify_old_oop and allow_dirty. Also reviewed by: alexlamsl@gmail.com Reviewed-by: jmasa, jwilhelm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
12236
51d6463cfd9d 7156764: Remove unused size parameter from some CollectedHeap methods
brutisso
parents: 11624
diff changeset
     2
 * Copyright (c) 1997, 2012, 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: 4584
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4584
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: 4584
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: 6176
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    26
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    27
#include "classfile/vmSymbols.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    28
#include "gc_interface/collectedHeap.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    29
#include "memory/oopFactory.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    30
#include "memory/resourceArea.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    31
#include "oops/instanceKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    32
#include "oops/klass.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    33
#include "oops/klassOop.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    34
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    35
#include "oops/oop.inline2.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6176
diff changeset
    36
#include "runtime/atomic.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    38
void Klass::set_name(Symbol* n) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    39
  _name = n;
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    40
  if (_name != NULL) _name->increment_refcount();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    41
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
bool Klass::is_subclass_of(klassOop k) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  // Run up the super chain and check
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  klassOop t = as_klassOop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  if (t == k) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  t = Klass::cast(t)->super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  while (t != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    if (t == k) return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    t = Klass::cast(t)->super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
bool Klass::search_secondary_supers(klassOop k) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  // Put some extra logic here out-of-line, before the search proper.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // This cuts down the size of the inline method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  // This is necessary, since I am never in my own secondary_super list.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  if (this->as_klassOop() == k)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // Scan the array-of-objects for a match
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  int cnt = secondary_supers()->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  for (int i = 0; i < cnt; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    if (secondary_supers()->obj_at(i) == k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
      ((Klass*)this)->set_secondary_super_cache(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
// Return self, except for abstract classes with exactly 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
// implementor.  Then return the 1 concrete implementation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
Klass *Klass::up_cast_abstract() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  Klass *r = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  while( r->is_abstract() ) {   // Receiver is abstract?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    Klass *s = r->subklass();   // Check for exactly 1 subklass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    if( !s || s->next_sibling() ) // Oops; wrong count; give up
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
      return this;              // Return 'this' as a no-progress flag
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    r = s;                    // Loop till find concrete class
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  return r;                   // Return the 1 concrete class
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1550
diff changeset
    88
// Find LCA in class hierarchy
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
Klass *Klass::LCA( Klass *k2 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  Klass *k1 = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  while( 1 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    if( k1->is_subtype_of(k2->as_klassOop()) ) return k2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    if( k2->is_subtype_of(k1->as_klassOop()) ) return k1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    k1 = k1->super()->klass_part();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    k2 = k2->super()->klass_part();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
void Klass::check_valid_for_instantiation(bool throwError, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  ResourceMark rm(THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
            : vmSymbols::java_lang_InstantiationException(), external_name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
void Klass::copy_array(arrayOop s, int src_pos, arrayOop d, int dst_pos, int length, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  THROW(vmSymbols::java_lang_ArrayStoreException());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
void Klass::initialize(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
bool Klass::compute_is_subtype_of(klassOop k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  assert(k->is_klass(), "argument must be a class");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  return is_subclass_of(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   122
methodOop Klass::uncached_lookup_method(Symbol* name, Symbol* signature) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  tty->print_cr("Error: uncached_lookup_method called on a klass oop."
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
                " Likely error: reflection method does not correctly"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
                " wrap return value in a mirror object.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
klassOop Klass::base_create_klass_oop(KlassHandle& klass, int size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
                                      const Klass_vtbl& vtbl, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  size = align_object_size(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  // allocate and initialize vtable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  Klass*   kl = (Klass*) vtbl.allocate_permanent(klass, size, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  klassOop k  = kl->as_klassOop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  { // Preinitialize supertype information.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    // A later call to initialize_supers() may update these settings:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    kl->set_super(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    for (juint i = 0; i < Klass::primary_super_limit(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      kl->_primary_supers[i] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    kl->set_secondary_supers(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    oop_store_without_check((oop*) &kl->_primary_supers[0], k);
11430
718fc06da49a 7118863: Move sizeof(klassOopDesc) into the *Klass::*_offset_in_bytes() functions
stefank
parents: 9172
diff changeset
   147
    kl->set_super_check_offset(in_bytes(primary_supers_offset()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  kl->set_java_mirror(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  kl->set_modifier_flags(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  kl->set_layout_helper(Klass::_lh_neutral_value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  kl->set_name(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  AccessFlags af;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  af.set_flags(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  kl->set_access_flags(af);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  kl->set_subklass(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  kl->set_next_sibling(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  kl->set_alloc_count(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  kl->set_alloc_size(0);
11480
1bf714e8adb4 7115199: Add event tracing hooks and Java Flight Recorder infrastructure
phh
parents: 9172
diff changeset
   161
  TRACE_SET_KLASS_TRACE_ID(kl, 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  kl->set_prototype_header(markOopDesc::prototype());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  kl->set_biased_lock_revocation_count(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  kl->set_last_biased_lock_bulk_revocation_time(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  return k;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
KlassHandle Klass::base_create_klass(KlassHandle& klass, int size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
                                     const Klass_vtbl& vtbl, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  klassOop ek = base_create_klass_oop(klass, size, vtbl, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  return KlassHandle(THREAD, ek);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
void Klass_vtbl::post_new_init_klass(KlassHandle& klass,
12236
51d6463cfd9d 7156764: Remove unused size parameter from some CollectedHeap methods
brutisso
parents: 11624
diff changeset
   177
                                     klassOop new_klass) const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  assert(!new_klass->klass_part()->null_vtbl(), "Not a complete klass");
12236
51d6463cfd9d 7156764: Remove unused size parameter from some CollectedHeap methods
brutisso
parents: 11624
diff changeset
   179
  CollectedHeap::post_allocation_install_obj_klass(klass, new_klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
void* Klass_vtbl::operator new(size_t ignored, KlassHandle& klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
                               int size, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  // The vtable pointer is installed during the execution of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // constructors in the call to permanent_obj_allocate().  Delay
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  // the installation of the klass pointer into the new klass "k"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  // until after the vtable pointer has been installed (i.e., until
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // after the return of permanent_obj_allocate().
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  klassOop k =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    (klassOop) CollectedHeap::permanent_obj_allocate_no_klass_install(klass,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      size, CHECK_NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  return k->klass_part();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
jint Klass::array_layout_helper(BasicType etype) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  assert(etype >= T_BOOLEAN && etype <= T_OBJECT, "valid etype");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  // Note that T_ARRAY is not allowed here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  int  hsize = arrayOopDesc::base_offset_in_bytes(etype);
202
dc13bf0e5d5d 6633953: type2aelembytes{T_ADDRESS} should be 8 bytes in 64 bit VM
kvn
parents: 1
diff changeset
   199
  int  esize = type2aelembytes(etype);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  bool isobj = (etype == T_OBJECT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  int  tag   =  isobj ? _lh_array_tag_obj_value : _lh_array_tag_type_value;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  int lh = array_layout_helper(tag, hsize, etype, exact_log2(esize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  assert(lh < (int)_lh_neutral_value, "must look like an array layout");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  assert(layout_helper_is_javaArray(lh), "correct kind");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  assert(layout_helper_is_objArray(lh) == isobj, "correct kind");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  assert(layout_helper_is_typeArray(lh) == !isobj, "correct kind");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  assert(layout_helper_header_size(lh) == hsize, "correct decode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  assert(layout_helper_element_type(lh) == etype, "correct decode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  assert(1 << layout_helper_log2_element_size(lh) == esize, "correct decode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  return lh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
bool Klass::can_be_primary_super_slow() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  if (super() == NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  else if (super()->klass_part()->super_depth() >= primary_super_limit()-1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
void Klass::initialize_supers(klassOop k, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  if (FastSuperclassLimit == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    // None of the other machinery matters.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    set_super(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  if (k == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    set_super(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
    oop_store_without_check((oop*) &_primary_supers[0], (oop) this->as_klassOop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    assert(super_depth() == 0, "Object must already be initialized properly");
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4094
diff changeset
   234
  } else if (k != super() || k == SystemDictionary::Object_klass()) {
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4094
diff changeset
   235
    assert(super() == NULL || super() == SystemDictionary::Object_klass(),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
           "initialize this only once to a non-trivial value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    set_super(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    Klass* sup = k->klass_part();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
    int sup_depth = sup->super_depth();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
    juint my_depth  = MIN2(sup_depth + 1, (int)primary_super_limit());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    if (!can_be_primary_super_slow())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
      my_depth = primary_super_limit();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    for (juint i = 0; i < my_depth; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
      oop_store_without_check((oop*) &_primary_supers[i], (oop) sup->_primary_supers[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    klassOop *super_check_cell;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    if (my_depth < primary_super_limit()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
      oop_store_without_check((oop*) &_primary_supers[my_depth], (oop) this->as_klassOop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
      super_check_cell = &_primary_supers[my_depth];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      // Overflow of the primary_supers array forces me to be secondary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      super_check_cell = &_secondary_super_cache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    set_super_check_offset((address)super_check_cell - (address) this->as_klassOop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      juint j = super_depth();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      assert(j == my_depth, "computed accessor gets right answer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      klassOop t = as_klassOop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      while (!Klass::cast(t)->can_be_primary_super()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
        t = Klass::cast(t)->super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
        j = Klass::cast(t)->super_depth();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
      for (juint j1 = j+1; j1 < primary_super_limit(); j1++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
        assert(primary_super_of_depth(j1) == NULL, "super list padding");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
      while (t != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
        assert(primary_super_of_depth(j) == t, "super list initialization");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
        t = Klass::cast(t)->super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
        --j;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
      assert(j == (juint)-1, "correct depth count");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  if (secondary_supers() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    KlassHandle this_kh (THREAD, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    // Now compute the list of secondary supertypes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    // Secondaries can occasionally be on the super chain,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    // if the inline "_primary_supers" array overflows.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    int extras = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    klassOop p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    for (p = super(); !(p == NULL || p->klass_part()->can_be_primary_super()); p = p->klass_part()->super()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
      ++extras;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    // Compute the "real" non-extra secondaries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    objArrayOop secondary_oops = compute_secondary_supers(extras, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    objArrayHandle secondaries (THREAD, secondary_oops);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    // Store the extra secondaries in the first array positions:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    int fillp = extras;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    for (p = this_kh->super(); !(p == NULL || p->klass_part()->can_be_primary_super()); p = p->klass_part()->super()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
      int i;                    // Scan for overflow primaries being duplicates of 2nd'arys
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
      // This happens frequently for very deeply nested arrays: the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
      // primary superclass chain overflows into the secondary.  The
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
      // secondary list contains the element_klass's secondaries with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
      // an extra array dimension added.  If the element_klass's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
      // secondary list already contains some primary overflows, they
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
      // (with the extra level of array-ness) will collide with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
      // normal primary superclass overflows.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
      for( i = extras; i < secondaries->length(); i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
        if( secondaries->obj_at(i) == p )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
      if( i < secondaries->length() )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
        continue;               // It's a dup, don't put it in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
      secondaries->obj_at_put(--fillp, p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    // See if we had some dup's, so the array has holes in it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    if( fillp > 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
      // Pack the array.  Drop the old secondaries array on the floor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
      // and let GC reclaim it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      objArrayOop s2 = oopFactory::new_system_objArray(secondaries->length() - fillp, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
      for( int i = 0; i < s2->length(); i++ )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
        s2->obj_at_put( i, secondaries->obj_at(i+fillp) );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
      secondaries = objArrayHandle(THREAD, s2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    if (secondaries() != Universe::the_array_interfaces_array()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
      // We must not copy any NULL placeholders left over from bootstrap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
      for (int j = 0; j < secondaries->length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
        assert(secondaries->obj_at(j) != NULL, "correct bootstrapping order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    this_kh->set_secondary_supers(secondaries());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
objArrayOop Klass::compute_secondary_supers(int num_extra_slots, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  assert(num_extra_slots == 0, "override for complex klasses");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  return Universe::the_empty_system_obj_array();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
Klass* Klass::subklass() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  return _subklass == NULL ? NULL : Klass::cast(_subklass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
instanceKlass* Klass::superklass() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  assert(super() == NULL || super()->klass_part()->oop_is_instance(), "must be instance klass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  return _super == NULL ? NULL : instanceKlass::cast(_super);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
Klass* Klass::next_sibling() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  return _next_sibling == NULL ? NULL : Klass::cast(_next_sibling);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
void Klass::set_subklass(klassOop s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  assert(s != as_klassOop(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  oop_store_without_check((oop*)&_subklass, s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
void Klass::set_next_sibling(klassOop s) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  assert(s != as_klassOop(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  oop_store_without_check((oop*)&_next_sibling, s);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
void Klass::append_to_sibling_list() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  debug_only(if (!SharedSkipVerify) as_klassOop()->verify();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  // add ourselves to superklass' subklass list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  instanceKlass* super = superklass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  if (super == NULL) return;        // special case: class Object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  assert(SharedSkipVerify ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
         (!super->is_interface()    // interfaces cannot be supers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
          && (super->superklass() == NULL || !is_interface())),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
         "an interface can only be a subklass of Object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  klassOop prev_first_subklass = super->subklass_oop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  if (prev_first_subklass != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    // set our sibling to be the superklass' previous first subklass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    set_next_sibling(prev_first_subklass);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  // make ourselves the superklass' first subklass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  super->set_subklass(as_klassOop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  debug_only(if (!SharedSkipVerify) as_klassOop()->verify();)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
void Klass::remove_from_sibling_list() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  // remove receiver from sibling list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  instanceKlass* super = superklass();
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4094
diff changeset
   387
  assert(super != NULL || as_klassOop() == SystemDictionary::Object_klass(), "should have super");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  if (super == NULL) return;        // special case: class Object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  if (super->subklass() == this) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
    // first subklass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    super->set_subklass(_next_sibling);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
    Klass* sib = super->subklass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    while (sib->next_sibling() != this) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
      sib = sib->next_sibling();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    sib->set_next_sibling(_next_sibling);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
void Klass::follow_weak_klass_links( BoolObjectClosure* is_alive, OopClosure* keep_alive) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  // This klass is alive but the subklass and siblings are not followed/updated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  // We update the subklass link and the subklass' sibling links here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  // Our own sibling link will be updated by our superclass (which must be alive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  // since we are).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  assert(is_alive->do_object_b(as_klassOop()), "just checking, this should be live");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  if (ClassUnloading) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
    klassOop sub = subklass_oop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
    if (sub != NULL && !is_alive->do_object_b(sub)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
      // first subklass not alive, find first one alive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
      do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
        if (TraceClassUnloading && WizardMode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
          ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
          tty->print_cr("[Unlinking class (subclass) %s]", sub->klass_part()->external_name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
        sub = sub->klass_part()->next_sibling_oop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
      } while (sub != NULL && !is_alive->do_object_b(sub));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
      set_subklass(sub);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    // now update the subklass' sibling list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
    while (sub != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
      klassOop next = sub->klass_part()->next_sibling_oop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
      if (next != NULL && !is_alive->do_object_b(next)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
        // first sibling not alive, find first one alive
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
        do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
          if (TraceClassUnloading && WizardMode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
            ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
            tty->print_cr("[Unlinking class (sibling) %s]", next->klass_part()->external_name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
          next = next->klass_part()->next_sibling_oop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
        } while (next != NULL && !is_alive->do_object_b(next));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
        sub->klass_part()->set_next_sibling(next);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
      sub = next;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    // Always follow subklass and sibling link. This will prevent any klasses from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    // being unloaded (all classes are transitively linked from java.lang.Object).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    keep_alive->do_oop(adr_subklass());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    keep_alive->do_oop(adr_next_sibling());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
void Klass::remove_unshareable_info() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  if (oop_is_instance()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    instanceKlass* ik = (instanceKlass*)this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    if (ik->is_linked()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
      ik->unlink_class();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  }
9172
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8921
diff changeset
   456
  // Clear the Java vtable if the oop has one.
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8921
diff changeset
   457
  // The vtable isn't shareable because it's in the wrong order wrt the methods
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8921
diff changeset
   458
  // once the method names get moved and resorted.
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8921
diff changeset
   459
  klassVtable* vt = vtable();
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8921
diff changeset
   460
  if (vt != NULL) {
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8921
diff changeset
   461
    assert(oop_is_instance() || oop_is_array(), "nothing else has vtable");
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8921
diff changeset
   462
    vt->clear_vtable();
a4e13ccafc44 7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents: 8921
diff changeset
   463
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  set_subklass(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  set_next_sibling(NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   469
void Klass::shared_symbols_iterate(SymbolClosure* closure) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   470
  closure->do_symbol(&_name);
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   471
}
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   472
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   473
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
klassOop Klass::array_klass_or_null(int rank) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  // No exception can be thrown by array_klass_impl when called with or_null == true.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  // (In anycase, the execption mark will fail if it do so)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  return array_klass_impl(true, rank, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
klassOop Klass::array_klass_or_null() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  // No exception can be thrown by array_klass_impl when called with or_null == true.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
  // (In anycase, the execption mark will fail if it do so)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  return array_klass_impl(true, THREAD);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
klassOop Klass::array_klass_impl(bool or_null, int rank, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  fatal("array_klass should be dispatched to instanceKlass, objArrayKlass or typeArrayKlass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
klassOop Klass::array_klass_impl(bool or_null, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  fatal("array_klass should be dispatched to instanceKlass, objArrayKlass or typeArrayKlass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
void Klass::with_array_klasses_do(void f(klassOop k)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  f(as_klassOop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
const char* Klass::external_name() const {
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   508
  if (oop_is_instance()) {
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   509
    instanceKlass* ik = (instanceKlass*) this;
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   510
    if (ik->is_anonymous()) {
8883
5569135acca3 6817525: turn on method handle functionality by default for JSR 292
twisti
parents: 8076
diff changeset
   511
      assert(EnableInvokeDynamic, "");
1550
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   512
      intptr_t hash = ik->java_mirror()->identity_hash();
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   513
      char     hash_buf[40];
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   514
      sprintf(hash_buf, "/" UINTX_FORMAT, (uintx)hash);
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   515
      size_t   hash_len = strlen(hash_buf);
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   516
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   517
      size_t result_len = name()->utf8_length();
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   518
      char*  result     = NEW_RESOURCE_ARRAY(char, result_len + hash_len + 1);
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   519
      name()->as_klass_external_name(result, (int) result_len + 1);
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   520
      assert(strlen(result) == result_len, "");
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   521
      strcpy(result + result_len, hash_buf);
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   522
      assert(strlen(result) == result_len + hash_len, "");
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   523
      return result;
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   524
    }
be2fc37a817f 6653858: dynamic languages need to be able to load anonymous classes
jrose
parents: 670
diff changeset
   525
  }
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 2131
diff changeset
   526
  if (name() == NULL)  return "<unknown>";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
  return name()->as_klass_external_name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
4094
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 2131
diff changeset
   531
const char* Klass::signature_name() const {
1f424b2b2171 6815692: method handle code needs some cleanup (post-6655638)
jrose
parents: 2131
diff changeset
   532
  if (name() == NULL)  return "<unknown>";
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  return name()->as_C_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
// Unless overridden, modifier_flags is 0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
jint Klass::compute_modifier_flags(TRAPS) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
int Klass::atomic_incr_biased_lock_revocation_count() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  return (int) Atomic::add(1, &_biased_lock_revocation_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
// Unless overridden, jvmti_class_status has no flags set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
jint Klass::jvmti_class_status() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
// Printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
void Klass::oop_print_on(oop obj, outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  // print title
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  st->print_cr("%s ", internal_name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  obj->print_address_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  if (WizardMode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
     // print header
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
     obj->mark()->print_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  // print class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  st->print(" - klass: ");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  obj->klass()->print_value_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
  st->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
void Klass::oop_print_value_on(oop obj, outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  // print title
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  ResourceMark rm;              // Cannot print in debug mode without this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  st->print("%s", internal_name());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  obj->print_address_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
// Verification
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
void Klass::oop_verify_on(oop obj, outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  guarantee(obj->is_oop(),  "should be oop");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  guarantee(obj->klass()->is_perm(),  "should be in permspace");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  guarantee(obj->klass()->is_klass(), "klass field is not a klass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
void Klass::verify_vtable_index(int i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  assert(oop_is_instance() || oop_is_array(), "only instanceKlass and arrayKlass have vtables");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  if (oop_is_instance()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
    assert(i>=0 && i<((instanceKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    assert(i>=0 && i<((arrayKlass*)this)->vtable_length()/vtableEntry::size(), "index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
#endif