hotspot/src/share/vm/ci/ciInstanceKlass.cpp
author stefank
Wed, 01 Dec 2010 15:04:06 +0100
changeset 7408 c04a5c989f26
parent 7397 5b173b4ca846
child 8076 96d498ec7ae1
permissions -rw-r--r--
7003125: precompiled.hpp is included when precompiled headers are not used Summary: Added an ifndef DONT_USE_PRECOMPILED_HEADER to precompiled.hpp. Set up DONT_USE_PRECOMPILED_HEADER when compiling with Sun Studio or when the user specifies USE_PRECOMPILED_HEADER=0. Fixed broken include dependencies. Reviewed-by: coleenp, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5925
a30fef61d0b7 6958668: repeated uncommon trapping for new of klass which is being initialized
never
parents: 5884
diff changeset
     2
 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4571
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7125
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7125
diff changeset
    26
#include "ci/ciField.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7125
diff changeset
    27
#include "ci/ciInstance.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7125
diff changeset
    28
#include "ci/ciInstanceKlass.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7125
diff changeset
    29
#include "ci/ciUtilities.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7125
diff changeset
    30
#include "classfile/systemDictionary.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7125
diff changeset
    31
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7125
diff changeset
    32
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7125
diff changeset
    33
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7125
diff changeset
    34
#include "runtime/fieldDescriptor.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// ciInstanceKlass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// This class represents a klassOop in the HotSpot virtual machine
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// whose Klass part in an instanceKlass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// ciInstanceKlass::ciInstanceKlass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// Loaded instance klass.
217
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
    45
ciInstanceKlass::ciInstanceKlass(KlassHandle h_k) :
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
    46
  ciKlass(h_k), _non_static_fields(NULL)
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
    47
{
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  assert(get_Klass()->oop_is_instance(), "wrong type");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  instanceKlass* ik = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  AccessFlags access_flags = ik->access_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  _flags = ciFlags(access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  _has_finalizer = access_flags.has_finalizer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  _has_subklass = ik->subklass() != NULL;
5925
a30fef61d0b7 6958668: repeated uncommon trapping for new of klass which is being initialized
never
parents: 5884
diff changeset
    55
  _init_state = (instanceKlass::ClassState)ik->get_init_state();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  _nonstatic_field_size = ik->nonstatic_field_size();
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
    57
  _has_nonstatic_fields = ik->has_nonstatic_fields();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  _nof_implementors = ik->nof_implementors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  for (int i = 0; i < implementors_limit; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    _implementors[i] = NULL;  // we will fill these lazily
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  Thread *thread = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  if (ciObjectFactory::is_initialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    _loader = JNIHandles::make_local(thread, ik->class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    _protection_domain = JNIHandles::make_local(thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
                                                ik->protection_domain());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    _is_shared = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    Handle h_loader(thread, ik->class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    Handle h_protection_domain(thread, ik->protection_domain());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    _loader = JNIHandles::make_global(h_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    _protection_domain = JNIHandles::make_global(h_protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    _is_shared = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // Lazy fields get filled in only upon request.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  _super  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  _java_mirror = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  if (is_shared()) {
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4567
diff changeset
    84
    if (h_k() != SystemDictionary::Object_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
      super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    java_mirror();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    //compute_nonstatic_fields();  // done outside of constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  _field_cache = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
// Version for unloaded classes:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
                                 jobject loader, jobject protection_domain)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  : ciKlass(name, ciInstanceKlassKlass::make())
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  assert(name->byte_at(0) != '[', "not an instance klass");
5925
a30fef61d0b7 6958668: repeated uncommon trapping for new of klass which is being initialized
never
parents: 5884
diff changeset
   100
  _init_state = (instanceKlass::ClassState)0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  _nonstatic_field_size = -1;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   102
  _has_nonstatic_fields = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  _nonstatic_fields = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  _nof_implementors = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  _loader = loader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  _protection_domain = protection_domain;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  _is_shared = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  _super = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  _java_mirror = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  _field_cache = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
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
// ciInstanceKlass::compute_shared_is_initialized
5925
a30fef61d0b7 6958668: repeated uncommon trapping for new of klass which is being initialized
never
parents: 5884
diff changeset
   117
void ciInstanceKlass::compute_shared_init_state() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  GUARDED_VM_ENTRY(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    instanceKlass* ik = get_instanceKlass();
5925
a30fef61d0b7 6958668: repeated uncommon trapping for new of klass which is being initialized
never
parents: 5884
diff changeset
   120
    _init_state = (instanceKlass::ClassState)ik->get_init_state();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
// ciInstanceKlass::compute_shared_has_subklass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
bool ciInstanceKlass::compute_shared_has_subklass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  GUARDED_VM_ENTRY(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    instanceKlass* ik = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    _has_subklass = ik->subklass() != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    return _has_subklass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
// ciInstanceKlass::compute_shared_nof_implementors
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
int ciInstanceKlass::compute_shared_nof_implementors() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  // We requery this property, since it is a very old ciObject.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  GUARDED_VM_ENTRY(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    instanceKlass* ik = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    _nof_implementors = ik->nof_implementors();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    return _nof_implementors;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
// ciInstanceKlass::loader
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
oop ciInstanceKlass::loader() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  ASSERT_IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  return JNIHandles::resolve(_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
// ciInstanceKlass::loader_handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
jobject ciInstanceKlass::loader_handle() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  return _loader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
// ciInstanceKlass::protection_domain
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
oop ciInstanceKlass::protection_domain() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  ASSERT_IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  return JNIHandles::resolve(_protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
// ciInstanceKlass::protection_domain_handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
jobject ciInstanceKlass::protection_domain_handle() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  return _protection_domain;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
// ciInstanceKlass::field_cache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
// Get the field cache associated with this klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
ciConstantPoolCache* ciInstanceKlass::field_cache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  if (is_shared()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  if (_field_cache == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    assert(!is_java_lang_Object(), "Object has no fields");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    Arena* arena = CURRENT_ENV->arena();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    _field_cache = new (arena) ciConstantPoolCache(arena, 5);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  return _field_cache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
// ciInstanceKlass::get_canonical_holder
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
ciInstanceKlass* ciInstanceKlass::get_canonical_holder(int offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  if (!(offset >= 0 && offset < layout_helper())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    tty->print("*** get_canonical_holder(%d) on ", offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    this->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    tty->print_cr(" ***");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  assert(offset >= 0 && offset < layout_helper(), "offset must be tame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   200
  if (offset < instanceOopDesc::base_offset_in_bytes()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    // All header offsets belong properly to java/lang/Object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    return CURRENT_ENV->Object_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  ciInstanceKlass* self = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  for (;;) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    assert(self->is_loaded(), "must be loaded to have size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    ciInstanceKlass* super = self->super();
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   209
    if (super == NULL || super->nof_nonstatic_fields() == 0 ||
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   210
        !super->contains_field_offset(offset)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
      return self;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
      self = super;  // return super->get_canonical_holder(offset)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    }
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
// ciInstanceKlass::is_java_lang_Object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
// Is this klass java.lang.Object?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
bool ciInstanceKlass::is_java_lang_Object() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  return equals(CURRENT_ENV->Object_klass());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
// ciInstanceKlass::uses_default_loader
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
bool ciInstanceKlass::uses_default_loader() {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   229
  // Note:  We do not need to resolve the handle or enter the VM
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   230
  // in order to test null-ness.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   231
  return _loader == NULL;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   232
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   233
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   234
// ------------------------------------------------------------------
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   235
// ciInstanceKlass::is_in_package
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   236
//
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   237
// Is this klass in the given package?
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   238
bool ciInstanceKlass::is_in_package(const char* packagename, int len) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   239
  // To avoid class loader mischief, this test always rejects application classes.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   240
  if (!uses_default_loader())
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   241
    return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   242
  GUARDED_VM_ENTRY(
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   243
    return is_in_package_impl(packagename, len);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   244
  )
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   245
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   246
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   247
bool ciInstanceKlass::is_in_package_impl(const char* packagename, int len) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   248
  ASSERT_IN_VM;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   249
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   250
  // If packagename contains trailing '/' exclude it from the
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   251
  // prefix-test since we test for it explicitly.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   252
  if (packagename[len - 1] == '/')
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   253
    len--;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   254
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   255
  if (!name()->starts_with(packagename, len))
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   256
    return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   257
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   258
  // Test if the class name is something like "java/lang".
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   259
  if ((len + 1) > name()->utf8_length())
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   260
    return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   261
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   262
  // Test for trailing '/'
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   263
  if ((char) name()->byte_at(len) != '/')
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   264
    return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   265
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   266
  // Make sure it's not actually in a subpackage:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   267
  if (name()->index_of_at(len+1, "/", 1) >= 0)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   268
    return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   269
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   270
  return true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
// ciInstanceKlass::print_impl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
// Implementation of the print method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
void ciInstanceKlass::print_impl(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  ciKlass::print_impl(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  GUARDED_VM_ENTRY(st->print(" loader=0x%x", (address)loader());)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  if (is_loaded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    st->print(" loaded=true initialized=%s finalized=%s subklass=%s size=%d flags=",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
              bool_to_str(is_initialized()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
              bool_to_str(has_finalizer()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
              bool_to_str(has_subklass()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
              layout_helper());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    _flags.print_klass_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
    if (_super) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
      st->print(" super=");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
      _super->print_name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
    if (_java_mirror) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
      st->print(" mirror=PRESENT");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    st->print(" loaded=false");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
// ciInstanceKlass::super
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
// Get the superklass of this klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
ciInstanceKlass* ciInstanceKlass::super() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  assert(is_loaded(), "must be loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  if (_super == NULL && !is_java_lang_Object()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    GUARDED_VM_ENTRY(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
      klassOop super_klass = get_instanceKlass()->super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
      _super = CURRENT_ENV->get_object(super_klass)->as_instance_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
    )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  return _super;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
// ciInstanceKlass::java_mirror
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
// Get the instance of java.lang.Class corresponding to this klass.
5884
3963019e3782 6960865: ldc of unloaded class throws an assert in ciTypeFlow
jrose
parents: 5882
diff changeset
   320
// Cache it on this->_java_mirror.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
ciInstance* ciInstanceKlass::java_mirror() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  if (_java_mirror == NULL) {
5884
3963019e3782 6960865: ldc of unloaded class throws an assert in ciTypeFlow
jrose
parents: 5882
diff changeset
   323
    _java_mirror = ciKlass::java_mirror();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  return _java_mirror;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
// ciInstanceKlass::unique_concrete_subklass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
ciInstanceKlass* ciInstanceKlass::unique_concrete_subklass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  if (!is_loaded())     return NULL; // No change if class is not loaded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  if (!is_abstract())   return NULL; // Only applies to abstract classes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  if (!has_subklass())  return NULL; // Must have at least one subklass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  instanceKlass* ik = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  Klass* up = ik->up_cast_abstract();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  assert(up->oop_is_instance(), "must be instanceKlass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  if (ik == up) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  return CURRENT_THREAD_ENV->get_object(up->as_klassOop())->as_instance_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
// ciInstanceKlass::has_finalizable_subclass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
bool ciInstanceKlass::has_finalizable_subclass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  if (!is_loaded())     return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  return Dependencies::find_finalizable_subclass(get_instanceKlass()) != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
// ciInstanceKlass::get_field_by_offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
ciField* ciInstanceKlass::get_field_by_offset(int field_offset, bool is_static) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  if (!is_static) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    for (int i = 0, len = nof_nonstatic_fields(); i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
      ciField* field = _nonstatic_fields->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
      int  field_off = field->offset_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
      if (field_off == field_offset)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
        return field;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
      if (field_off > field_offset)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
      // could do binary search or check bins, but probably not worth it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  instanceKlass* k = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  fieldDescriptor fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  if (!k->find_field_from_offset(field_offset, is_static, &fd)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
  ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  return field;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
217
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   377
// ------------------------------------------------------------------
4450
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   378
// ciInstanceKlass::get_field_by_name
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   379
ciField* ciInstanceKlass::get_field_by_name(ciSymbol* name, ciSymbol* signature, bool is_static) {
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   380
  VM_ENTRY_MARK;
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   381
  instanceKlass* k = get_instanceKlass();
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   382
  fieldDescriptor fd;
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   383
  klassOop def = k->find_field(name->get_symbolOop(), signature->get_symbolOop(), is_static, &fd);
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   384
  if (def == NULL) {
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   385
    return NULL;
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   386
  }
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   387
  ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   388
  return field;
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   389
}
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   390
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   391
// ------------------------------------------------------------------
217
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   392
// ciInstanceKlass::non_static_fields.
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   393
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   394
class NonStaticFieldFiller: public FieldClosure {
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   395
  GrowableArray<ciField*>* _arr;
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   396
  ciEnv* _curEnv;
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   397
public:
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   398
  NonStaticFieldFiller(ciEnv* curEnv, GrowableArray<ciField*>* arr) :
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   399
    _curEnv(curEnv), _arr(arr)
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   400
  {}
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   401
  void do_field(fieldDescriptor* fd) {
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   402
    ciField* field = new (_curEnv->arena()) ciField(fd);
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   403
    _arr->append(field);
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   404
  }
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   405
};
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   406
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   407
GrowableArray<ciField*>* ciInstanceKlass::non_static_fields() {
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   408
  if (_non_static_fields == NULL) {
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   409
    VM_ENTRY_MARK;
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   410
    ciEnv* curEnv = ciEnv::current();
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   411
    instanceKlass* ik = get_instanceKlass();
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   412
    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
   413
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5925
diff changeset
   414
    Arena* arena = curEnv->arena();
217
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   415
    _non_static_fields =
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5925
diff changeset
   416
      new (arena) GrowableArray<ciField*>(arena, max_n_fields, 0, NULL);
217
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   417
    NonStaticFieldFiller filler(curEnv, _non_static_fields);
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   418
    ik->do_nonstatic_fields(&filler);
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   419
  }
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   420
  return _non_static_fields;
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   421
}
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   422
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
static int sort_field_by_offset(ciField** a, ciField** b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  return (*a)->offset_in_bytes() - (*b)->offset_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  // (no worries about 32-bit overflow...)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
// ciInstanceKlass::compute_nonstatic_fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
int ciInstanceKlass::compute_nonstatic_fields() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  assert(is_loaded(), "must be loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  if (_nonstatic_fields != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
    return _nonstatic_fields->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   436
  if (!has_nonstatic_fields()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
    Arena* arena = CURRENT_ENV->arena();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    _nonstatic_fields = new (arena) GrowableArray<ciField*>(arena, 0, 0, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  assert(!is_java_lang_Object(), "bootstrap OK");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   443
  // Size in bytes of my fields, including inherited fields.
591
04d2e26e6d69 6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents: 360
diff changeset
   444
  int fsize = nonstatic_field_size() * heapOopSize;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   445
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  ciInstanceKlass* super = this->super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  GrowableArray<ciField*>* super_fields = NULL;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   448
  if (super != NULL && super->has_nonstatic_fields()) {
591
04d2e26e6d69 6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents: 360
diff changeset
   449
    int super_fsize  = super->nonstatic_field_size() * heapOopSize;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   450
    int super_flen   = super->nof_nonstatic_fields();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    super_fields = super->_nonstatic_fields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    assert(super_flen == 0 || super_fields != NULL, "first get nof_fields");
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   453
    // See if I am no larger than my super; if so, I can use his fields.
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   454
    if (fsize == super_fsize) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   455
      _nonstatic_fields = super_fields;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   456
      return super_fields->length();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   457
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  GrowableArray<ciField*>* fields = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  GUARDED_VM_ENTRY({
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
      fields = compute_nonstatic_fields_impl(super_fields);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
    });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  if (fields == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
    // This can happen if this class (java.lang.Class) has invisible fields.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
    _nonstatic_fields = super_fields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    return super_fields->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  int flen = fields->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  // Now sort them by offset, ascending.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  // (In principle, they could mix with superclass fields.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
  fields->sort(sort_field_by_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
#ifdef ASSERT
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   477
  int last_offset = instanceOopDesc::base_offset_in_bytes();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
  for (int i = 0; i < fields->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    ciField* field = fields->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
    int offset = field->offset_in_bytes();
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   481
    int size   = (field->_type == NULL) ? heapOopSize : field->size_in_bytes();
6772
2563324665d5 6829194: JSR 292 needs to support compressed oops
twisti
parents: 6180
diff changeset
   482
    assert(last_offset <= offset, err_msg("no field overlap: %d <= %d", last_offset, offset));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
    if (last_offset > (int)sizeof(oopDesc))
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
      assert((offset - last_offset) < BytesPerLong, "no big holes");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    // Note:  Two consecutive T_BYTE fields will be separated by wordSize-1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    // padding bytes if one of them is declared by a superclass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    // This is a minor inefficiency classFileParser.cpp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
    last_offset = offset + size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  }
591
04d2e26e6d69 6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents: 360
diff changeset
   490
  assert(last_offset <= (int)instanceOopDesc::base_offset_in_bytes() + fsize, "no overflow");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  _nonstatic_fields = fields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  return flen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
GrowableArray<ciField*>*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
                                               super_fields) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  ASSERT_IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  Arena* arena = CURRENT_ENV->arena();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
  int flen = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  GrowableArray<ciField*>* fields = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  instanceKlass* k = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
  typeArrayOop fields_array = k->fields();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  for (int pass = 0; pass <= 1; pass++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
    for (int i = 0, alen = fields_array->length(); i < alen; i += instanceKlass::next_offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
      fieldDescriptor fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
      fd.initialize(k->as_klassOop(), i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
      if (fd.is_static())  continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
      if (pass == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
        flen += 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
        ciField* field = new (arena) ciField(&fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
        fields->append(field);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
    // Between passes, allocate the array:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
    if (pass == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
      if (flen == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
        return NULL;  // return nothing if none are locally declared
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
      if (super_fields != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
        flen += super_fields->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
      if (super_fields != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
        fields->appendAll(super_fields);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  assert(fields->length() == flen, "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
  return fields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
// ciInstanceKlass::find_method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
// Find a method in this klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
ciMethod* ciInstanceKlass::find_method(ciSymbol* name, ciSymbol* signature) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  instanceKlass* k = get_instanceKlass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  symbolOop name_sym = name->get_symbolOop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  symbolOop sig_sym= signature->get_symbolOop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  methodOop m = k->find_method(name_sym, sig_sym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  if (m == NULL)  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  return CURRENT_THREAD_ENV->get_object(m)->as_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
// ciInstanceKlass::is_leaf_type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
bool ciInstanceKlass::is_leaf_type() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  assert(is_loaded(), "must be loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  if (is_shared()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
    return is_final();  // approximately correct
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    return !_has_subklass && (_nof_implementors == 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
// ciInstanceKlass::implementor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
// Report an implementor of this interface.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
// Returns NULL if exact information is not available.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
// Note that there are various races here, since my copy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
// of _nof_implementors might be out of date with respect
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
// to results returned by instanceKlass::implementor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
// This is OK, since any dependencies we decide to assert
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
// will be checked later under the Compile_lock.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
ciInstanceKlass* ciInstanceKlass::implementor(int n) {
7125
f088bb3df36d 6839891: Array overrun in vm ci
kvn
parents: 6772
diff changeset
   575
  if (n >= implementors_limit) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  ciInstanceKlass* impl = _implementors[n];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  if (impl == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
    if (_nof_implementors > implementors_limit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
    // Go into the VM to fetch the implementor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
      VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
      klassOop k = get_instanceKlass()->implementor(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
      if (k != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
        impl = CURRENT_THREAD_ENV->get_object(k)->as_instance_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    // Memoize this result.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
    if (!is_shared()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
      _implementors[n] = (impl == NULL)? this: impl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  } else if (impl == this) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
    impl = NULL;  // memoized null result from a VM query
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  return impl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
}