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