hotspot/src/share/vm/ci/ciInstanceKlass.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 217 c646ef2f5d58
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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/_ciInstanceKlass.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// ciInstanceKlass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// This class represents a klassOop in the HotSpot virtual machine
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// whose Klass part in an instanceKlass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// ciInstanceKlass::ciInstanceKlass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// Loaded instance klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
ciInstanceKlass::ciInstanceKlass(KlassHandle h_k) : ciKlass(h_k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  assert(get_Klass()->oop_is_instance(), "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  instanceKlass* ik = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  AccessFlags access_flags = ik->access_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  _flags = ciFlags(access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  _has_finalizer = access_flags.has_finalizer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  _has_subklass = ik->subklass() != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  _is_initialized = ik->is_initialized();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  // Next line must follow and use the result of the previous line:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  _is_linked = _is_initialized || ik->is_linked();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  _nonstatic_field_size = ik->nonstatic_field_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  _nof_implementors = ik->nof_implementors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  for (int i = 0; i < implementors_limit; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    _implementors[i] = NULL;  // we will fill these lazily
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  Thread *thread = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  if (ciObjectFactory::is_initialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    _loader = JNIHandles::make_local(thread, ik->class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    _protection_domain = JNIHandles::make_local(thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
                                                ik->protection_domain());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    _is_shared = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    Handle h_loader(thread, ik->class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    Handle h_protection_domain(thread, ik->protection_domain());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    _loader = JNIHandles::make_global(h_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    _protection_domain = JNIHandles::make_global(h_protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    _is_shared = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // Lazy fields get filled in only upon request.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  _super  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  _java_mirror = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  if (is_shared()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    if (h_k() != SystemDictionary::object_klass()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    java_mirror();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    //compute_nonstatic_fields();  // done outside of constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  _field_cache = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
// Version for unloaded classes:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
                                 jobject loader, jobject protection_domain)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  : ciKlass(name, ciInstanceKlassKlass::make())
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  assert(name->byte_at(0) != '[', "not an instance klass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  _is_initialized = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  _is_linked = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  _nonstatic_field_size = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  _nonstatic_fields = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  _nof_implementors = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  _loader = loader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  _protection_domain = protection_domain;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  _is_shared = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  _super = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  _java_mirror = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  _field_cache = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
}
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
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
// ciInstanceKlass::compute_shared_is_initialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
bool ciInstanceKlass::compute_shared_is_initialized() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  GUARDED_VM_ENTRY(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    instanceKlass* ik = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    _is_initialized = ik->is_initialized();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    return _is_initialized;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
// ciInstanceKlass::compute_shared_is_linked
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
bool ciInstanceKlass::compute_shared_is_linked() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  GUARDED_VM_ENTRY(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    instanceKlass* ik = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    _is_linked = ik->is_linked();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    return _is_linked;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  )
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
// ciInstanceKlass::compute_shared_has_subklass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
bool ciInstanceKlass::compute_shared_has_subklass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  GUARDED_VM_ENTRY(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    instanceKlass* ik = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    _has_subklass = ik->subklass() != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    return _has_subklass;
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
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
// ciInstanceKlass::compute_shared_nof_implementors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
int ciInstanceKlass::compute_shared_nof_implementors() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // We requery this property, since it is a very old ciObject.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  GUARDED_VM_ENTRY(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    instanceKlass* ik = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    _nof_implementors = ik->nof_implementors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    return _nof_implementors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
// ciInstanceKlass::loader
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
oop ciInstanceKlass::loader() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  ASSERT_IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  return JNIHandles::resolve(_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
// ciInstanceKlass::loader_handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
jobject ciInstanceKlass::loader_handle() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  return _loader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
// ciInstanceKlass::protection_domain
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
oop ciInstanceKlass::protection_domain() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  ASSERT_IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  return JNIHandles::resolve(_protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
// ciInstanceKlass::protection_domain_handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
jobject ciInstanceKlass::protection_domain_handle() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  return _protection_domain;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
// ciInstanceKlass::field_cache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
// Get the field cache associated with this klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
ciConstantPoolCache* ciInstanceKlass::field_cache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  if (is_shared()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  if (_field_cache == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    assert(!is_java_lang_Object(), "Object has no fields");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    Arena* arena = CURRENT_ENV->arena();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    _field_cache = new (arena) ciConstantPoolCache(arena, 5);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  return _field_cache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
// ciInstanceKlass::get_canonical_holder
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
ciInstanceKlass* ciInstanceKlass::get_canonical_holder(int offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  if (!(offset >= 0 && offset < layout_helper())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    tty->print("*** get_canonical_holder(%d) on ", offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    this->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    tty->print_cr(" ***");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  assert(offset >= 0 && offset < layout_helper(), "offset must be tame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  if (offset < (instanceOopDesc::header_size() * wordSize)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    // All header offsets belong properly to java/lang/Object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    return CURRENT_ENV->Object_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  ciInstanceKlass* self = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  for (;;) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    assert(self->is_loaded(), "must be loaded to have size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    ciInstanceKlass* super = self->super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    if (super == NULL || !super->contains_field_offset(offset)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
      return self;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
      self = super;  // return super->get_canonical_holder(offset)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
// ciInstanceKlass::is_java_lang_Object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
// Is this klass java.lang.Object?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
bool ciInstanceKlass::is_java_lang_Object() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  return equals(CURRENT_ENV->Object_klass());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
// ciInstanceKlass::uses_default_loader
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
bool ciInstanceKlass::uses_default_loader() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  return loader() == NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
// ciInstanceKlass::print_impl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
// Implementation of the print method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
void ciInstanceKlass::print_impl(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  ciKlass::print_impl(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  GUARDED_VM_ENTRY(st->print(" loader=0x%x", (address)loader());)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  if (is_loaded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    st->print(" loaded=true initialized=%s finalized=%s subklass=%s size=%d flags=",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
              bool_to_str(is_initialized()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
              bool_to_str(has_finalizer()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
              bool_to_str(has_subklass()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
              layout_helper());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
    _flags.print_klass_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    if (_super) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      st->print(" super=");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      _super->print_name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
    if (_java_mirror) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      st->print(" mirror=PRESENT");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
    st->print(" loaded=false");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
// ciInstanceKlass::super
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
// Get the superklass of this klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
ciInstanceKlass* ciInstanceKlass::super() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  assert(is_loaded(), "must be loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  if (_super == NULL && !is_java_lang_Object()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    GUARDED_VM_ENTRY(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
      klassOop super_klass = get_instanceKlass()->super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      _super = CURRENT_ENV->get_object(super_klass)->as_instance_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  return _super;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
// ciInstanceKlass::java_mirror
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
// Get the instance of java.lang.Class corresponding to this klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
ciInstance* ciInstanceKlass::java_mirror() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  assert(is_loaded(), "must be loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  if (_java_mirror == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    _java_mirror = ciKlass::java_mirror();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  return _java_mirror;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
// ciInstanceKlass::unique_concrete_subklass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
ciInstanceKlass* ciInstanceKlass::unique_concrete_subklass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  if (!is_loaded())     return NULL; // No change if class is not loaded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  if (!is_abstract())   return NULL; // Only applies to abstract classes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  if (!has_subklass())  return NULL; // Must have at least one subklass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  instanceKlass* ik = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  Klass* up = ik->up_cast_abstract();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  assert(up->oop_is_instance(), "must be instanceKlass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  if (ik == up) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  return CURRENT_THREAD_ENV->get_object(up->as_klassOop())->as_instance_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
// ciInstanceKlass::has_finalizable_subclass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
bool ciInstanceKlass::has_finalizable_subclass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  if (!is_loaded())     return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  return Dependencies::find_finalizable_subclass(get_instanceKlass()) != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
// ciInstanceKlass::get_field_by_offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
ciField* ciInstanceKlass::get_field_by_offset(int field_offset, bool is_static) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  if (!is_static) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    for (int i = 0, len = nof_nonstatic_fields(); i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
      ciField* field = _nonstatic_fields->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
      int  field_off = field->offset_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
      if (field_off == field_offset)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
        return field;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
      if (field_off > field_offset)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
      // could do binary search or check bins, but probably not worth it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  instanceKlass* k = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  fieldDescriptor fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  if (!k->find_field_from_offset(field_offset, is_static, &fd)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  return field;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
static int sort_field_by_offset(ciField** a, ciField** b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  return (*a)->offset_in_bytes() - (*b)->offset_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  // (no worries about 32-bit overflow...)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
// ciInstanceKlass::compute_nonstatic_fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
int ciInstanceKlass::compute_nonstatic_fields() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  assert(is_loaded(), "must be loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  if (_nonstatic_fields != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    return _nonstatic_fields->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  // Size in bytes of my fields, including inherited fields.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  // About equal to size_helper() - sizeof(oopDesc).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  int fsize = nonstatic_field_size() * wordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  if (fsize == 0) {     // easy shortcut
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    Arena* arena = CURRENT_ENV->arena();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    _nonstatic_fields = new (arena) GrowableArray<ciField*>(arena, 0, 0, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  assert(!is_java_lang_Object(), "bootstrap OK");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  ciInstanceKlass* super = this->super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  int      super_fsize = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  int      super_flen  = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  GrowableArray<ciField*>* super_fields = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  if (super != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    super_fsize  = super->nonstatic_field_size() * wordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    super_flen   = super->nof_nonstatic_fields();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    super_fields = super->_nonstatic_fields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    assert(super_flen == 0 || super_fields != NULL, "first get nof_fields");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  // See if I am no larger than my super; if so, I can use his fields.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  if (fsize == super_fsize) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    _nonstatic_fields = super_fields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
    return super_fields->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  GrowableArray<ciField*>* fields = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  GUARDED_VM_ENTRY({
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
      fields = compute_nonstatic_fields_impl(super_fields);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
    });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  if (fields == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    // This can happen if this class (java.lang.Class) has invisible fields.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    _nonstatic_fields = super_fields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
    return super_fields->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  int flen = fields->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  // Now sort them by offset, ascending.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  // (In principle, they could mix with superclass fields.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  fields->sort(sort_field_by_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  int last_offset = sizeof(oopDesc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  for (int i = 0; i < fields->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    ciField* field = fields->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
    int offset = field->offset_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    int size   = (field->_type == NULL) ? oopSize : field->size_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    assert(last_offset <= offset, "no field overlap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    if (last_offset > (int)sizeof(oopDesc))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
      assert((offset - last_offset) < BytesPerLong, "no big holes");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    // Note:  Two consecutive T_BYTE fields will be separated by wordSize-1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    // padding bytes if one of them is declared by a superclass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    // This is a minor inefficiency classFileParser.cpp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
    last_offset = offset + size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  assert(last_offset <= (int)sizeof(oopDesc) + fsize, "no overflow");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  _nonstatic_fields = fields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  return flen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
GrowableArray<ciField*>*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
                                               super_fields) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  ASSERT_IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  Arena* arena = CURRENT_ENV->arena();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  int flen = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  GrowableArray<ciField*>* fields = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  instanceKlass* k = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  typeArrayOop fields_array = k->fields();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  for (int pass = 0; pass <= 1; pass++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    for (int i = 0, alen = fields_array->length(); i < alen; i += instanceKlass::next_offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
      fieldDescriptor fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
      fd.initialize(k->as_klassOop(), i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
      if (fd.is_static())  continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
      if (pass == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
        flen += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
        ciField* field = new (arena) ciField(&fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
        fields->append(field);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
    // Between passes, allocate the array:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    if (pass == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
      if (flen == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
        return NULL;  // return nothing if none are locally declared
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
      if (super_fields != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
        flen += super_fields->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
      fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
      if (super_fields != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
        fields->appendAll(super_fields);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  assert(fields->length() == flen, "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  return fields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
// ciInstanceKlass::find_method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
// Find a method in this klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
ciMethod* ciInstanceKlass::find_method(ciSymbol* name, ciSymbol* signature) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  instanceKlass* k = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  symbolOop name_sym = name->get_symbolOop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  symbolOop sig_sym= signature->get_symbolOop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  methodOop m = k->find_method(name_sym, sig_sym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  if (m == NULL)  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  return CURRENT_THREAD_ENV->get_object(m)->as_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
// ciInstanceKlass::is_leaf_type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
bool ciInstanceKlass::is_leaf_type() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  assert(is_loaded(), "must be loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  if (is_shared()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    return is_final();  // approximately correct
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    return !_has_subklass && (_nof_implementors == 0);
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
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
// ciInstanceKlass::implementor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
// Report an implementor of this interface.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
// Returns NULL if exact information is not available.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
// Note that there are various races here, since my copy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
// of _nof_implementors might be out of date with respect
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
// to results returned by instanceKlass::implementor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
// This is OK, since any dependencies we decide to assert
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
// will be checked later under the Compile_lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
ciInstanceKlass* ciInstanceKlass::implementor(int n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  if (n > implementors_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  ciInstanceKlass* impl = _implementors[n];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  if (impl == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
    if (_nof_implementors > implementors_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
    // Go into the VM to fetch the implementor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
      VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
      klassOop k = get_instanceKlass()->implementor(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
      if (k != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
        impl = CURRENT_THREAD_ENV->get_object(k)->as_instance_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
    // Memoize this result.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
    if (!is_shared()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
      _implementors[n] = (impl == NULL)? this: impl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  } else if (impl == this) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    impl = NULL;  // memoized null result from a VM query
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  return impl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
}