hotspot/src/share/vm/ci/ciInstanceKlass.cpp
author vlivanov
Mon, 13 Feb 2017 23:58:00 +0300
changeset 43951 c23519aaccc1
parent 41669 2091069b6851
child 44738 11431bbc9549
child 46329 53ccc37bda19
permissions -rw-r--r--
8174818: bigapps/Weblogic12medrec fails with assert(check_call_consistency(jvms, cg)) failed: inconsistent info Reviewed-by: vlivanov Contributed-by: dmitry.chuyko@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 33611
diff changeset
     2
 * Copyright (c) 1999, 2016, 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"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 33611
diff changeset
    33
#include "memory/resourceArea.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7125
diff changeset
    34
#include "oops/oop.inline.hpp"
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
    35
#include "oops/fieldStreams.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 7125
diff changeset
    36
#include "runtime/fieldDescriptor.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// ciInstanceKlass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
    40
// This class represents a Klass* in the HotSpot virtual machine
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
    41
// whose Klass part in an InstanceKlass.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// ciInstanceKlass::ciInstanceKlass
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// Loaded instance klass.
217
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
    47
ciInstanceKlass::ciInstanceKlass(KlassHandle h_k) :
26706
1e985d72c57f 8058452: ciInstanceKlass::non_static_fields() can be removed
anoll
parents: 24424
diff changeset
    48
  ciKlass(h_k)
217
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
    49
{
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 31519
diff changeset
    50
  assert(get_Klass()->is_instance_klass(), "wrong type");
8314
057b1c20fd7e 6354181: nsk.logging.stress.threads.scmhml001 fails assertion in "src/share/vm/oops/instanceKlass.cpp, 111"
never
parents: 8076
diff changeset
    51
  assert(get_instanceKlass()->is_loaded(), "must be at least loaded");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
    52
  InstanceKlass* ik = get_instanceKlass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  AccessFlags access_flags = ik->access_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  _flags = ciFlags(access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  _has_finalizer = access_flags.has_finalizer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  _has_subklass = ik->subklass() != NULL;
11407
5399831730cd 7117052: instanceKlass::_init_state can be u1 type
coleenp
parents: 10546
diff changeset
    58
  _init_state = ik->init_state();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  _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
    60
  _has_nonstatic_fields = ik->has_nonstatic_fields();
41669
2091069b6851 8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents: 37248
diff changeset
    61
  _has_nonstatic_concrete_methods = ik->has_nonstatic_concrete_methods();
31519
bb26c50aadd0 8087218: Constant fold loads from final instance fields in VM anonymous classes
vlivanov
parents: 31037
diff changeset
    62
  _is_anonymous = ik->is_anonymous();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  _nonstatic_fields = NULL; // initialized lazily by compute_nonstatic_fields:
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
    64
  _has_injected_fields = -1;
12369
48fd3da4025c 7154670: The instanceKlass _implementors[] and _nof_implementors are not needed for non-interface klass.
jiangli
parents: 11407
diff changeset
    65
  _implementor = NULL; // we will fill these lazily
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  Thread *thread = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  if (ciObjectFactory::is_initialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    _loader = JNIHandles::make_local(thread, ik->class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    _protection_domain = JNIHandles::make_local(thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
                                                ik->protection_domain());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    _is_shared = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    Handle h_loader(thread, ik->class_loader());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    Handle h_protection_domain(thread, ik->protection_domain());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    _loader = JNIHandles::make_global(h_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    _protection_domain = JNIHandles::make_global(h_protection_domain);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    _is_shared = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // Lazy fields get filled in only upon request.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  _super  = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  _java_mirror = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  if (is_shared()) {
4571
80b553bddc26 6914300: ciEnv should export all well known classes
never
parents: 4567
diff changeset
    86
    if (h_k() != SystemDictionary::Object_klass()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
      super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    //compute_nonstatic_fields();  // done outside of constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  _field_cache = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
// Version for unloaded classes:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
ciInstanceKlass::ciInstanceKlass(ciSymbol* name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
                                 jobject loader, jobject protection_domain)
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
    98
  : ciKlass(name, T_OBJECT)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  assert(name->byte_at(0) != '[', "not an instance klass");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   101
  _init_state = (InstanceKlass::ClassState)0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  _nonstatic_field_size = -1;
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   103
  _has_nonstatic_fields = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  _nonstatic_fields = NULL;
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
   105
  _has_injected_fields = -1;
31519
bb26c50aadd0 8087218: Constant fold loads from final instance fields in VM anonymous classes
vlivanov
parents: 31037
diff changeset
   106
  _is_anonymous = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  _loader = loader;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  _protection_domain = protection_domain;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  _is_shared = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  _super = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  _java_mirror = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  _field_cache = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
// ciInstanceKlass::compute_shared_is_initialized
5925
a30fef61d0b7 6958668: repeated uncommon trapping for new of klass which is being initialized
never
parents: 5884
diff changeset
   119
void ciInstanceKlass::compute_shared_init_state() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  GUARDED_VM_ENTRY(
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   121
    InstanceKlass* ik = get_instanceKlass();
11407
5399831730cd 7117052: instanceKlass::_init_state can be u1 type
coleenp
parents: 10546
diff changeset
   122
    _init_state = ik->init_state();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// ciInstanceKlass::compute_shared_has_subklass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
bool ciInstanceKlass::compute_shared_has_subklass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  GUARDED_VM_ENTRY(
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   130
    InstanceKlass* ik = get_instanceKlass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    _has_subklass = ik->subklass() != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    return _has_subklass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
// ciInstanceKlass::loader
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
oop ciInstanceKlass::loader() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  ASSERT_IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  return JNIHandles::resolve(_loader);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
// ciInstanceKlass::loader_handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
jobject ciInstanceKlass::loader_handle() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  return _loader;
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::protection_domain
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
oop ciInstanceKlass::protection_domain() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  ASSERT_IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  return JNIHandles::resolve(_protection_domain);
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::protection_domain_handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
jobject ciInstanceKlass::protection_domain_handle() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  return _protection_domain;
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::field_cache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
// Get the field cache associated with this klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
ciConstantPoolCache* ciInstanceKlass::field_cache() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  if (is_shared()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  if (_field_cache == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    assert(!is_java_lang_Object(), "Object has no fields");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    Arena* arena = CURRENT_ENV->arena();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    _field_cache = new (arena) ciConstantPoolCache(arena, 5);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  return _field_cache;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
// ciInstanceKlass::get_canonical_holder
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
ciInstanceKlass* ciInstanceKlass::get_canonical_holder(int offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  if (!(offset >= 0 && offset < layout_helper())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    tty->print("*** get_canonical_holder(%d) on ", offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    this->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    tty->print_cr(" ***");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  assert(offset >= 0 && offset < layout_helper(), "offset must be tame");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   191
  if (offset < instanceOopDesc::base_offset_in_bytes()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    // All header offsets belong properly to java/lang/Object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    return CURRENT_ENV->Object_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  ciInstanceKlass* self = this;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  for (;;) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    assert(self->is_loaded(), "must be loaded to have size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    ciInstanceKlass* super = self->super();
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   200
    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
   201
        !super->contains_field_offset(offset)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      return self;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
      self = super;  // return super->get_canonical_holder(offset)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
// ciInstanceKlass::is_java_lang_Object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
// Is this klass java.lang.Object?
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   213
bool ciInstanceKlass::is_java_lang_Object() const {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  return equals(CURRENT_ENV->Object_klass());
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
// ciInstanceKlass::uses_default_loader
17383
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   219
bool ciInstanceKlass::uses_default_loader() const {
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   220
  // 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
   221
  // in order to test null-ness.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   222
  return _loader == NULL;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   223
}
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   224
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   225
// ------------------------------------------------------------------
17383
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   226
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   227
/**
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   228
 * Return basic type of boxed value for box klass or T_OBJECT if not.
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   229
 */
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   230
BasicType ciInstanceKlass::box_klass_type() const {
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   231
  if (uses_default_loader() && is_loaded()) {
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   232
    return SystemDictionary::box_klass_type(get_Klass());
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   233
  } else {
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   234
    return T_OBJECT;
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   235
  }
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   236
}
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   237
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   238
/**
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   239
 * Is this boxing klass?
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   240
 */
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   241
bool ciInstanceKlass::is_box_klass() const {
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   242
  return is_java_primitive(box_klass_type());
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   243
}
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   244
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   245
/**
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   246
 *  Is this boxed value offset?
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   247
 */
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   248
bool ciInstanceKlass::is_boxed_value_offset(int offset) const {
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   249
  BasicType bt = box_klass_type();
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   250
  return is_java_primitive(bt) &&
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   251
         (offset == java_lang_boxing_object::value_offset_in_bytes(bt));
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   252
}
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   253
3665c0901a0d 6934604: enable parts of EliminateAutoBox by default
kvn
parents: 15471
diff changeset
   254
// ------------------------------------------------------------------
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   255
// ciInstanceKlass::is_in_package
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   256
//
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   257
// Is this klass in the given package?
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   258
bool ciInstanceKlass::is_in_package(const char* packagename, int len) {
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   259
  // 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
   260
  if (!uses_default_loader())
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   261
    return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   262
  GUARDED_VM_ENTRY(
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   263
    return is_in_package_impl(packagename, len);
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   264
  )
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
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   267
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
   268
  ASSERT_IN_VM;
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
  // If packagename contains trailing '/' exclude it from the
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   271
  // prefix-test since we test for it explicitly.
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   272
  if (packagename[len - 1] == '/')
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   273
    len--;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   274
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   275
  if (!name()->starts_with(packagename, len))
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   276
    return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   277
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   278
  // Test if the class name is something like "java/lang".
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   279
  if ((len + 1) > name()->utf8_length())
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   280
    return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   281
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   282
  // Test for trailing '/'
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   283
  if ((char) name()->byte_at(len) != '/')
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   284
    return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   285
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   286
  // Make sure it's not actually in a subpackage:
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   287
  if (name()->index_of_at(len+1, "/", 1) >= 0)
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   288
    return false;
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   289
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4450
diff changeset
   290
  return true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
// ciInstanceKlass::print_impl
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
// Implementation of the print method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
void ciInstanceKlass::print_impl(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  ciKlass::print_impl(st);
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 21209
diff changeset
   299
  GUARDED_VM_ENTRY(st->print(" loader=" INTPTR_FORMAT, p2i((address)loader()));)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  if (is_loaded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
    st->print(" loaded=true initialized=%s finalized=%s subklass=%s size=%d flags=",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
              bool_to_str(is_initialized()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
              bool_to_str(has_finalizer()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
              bool_to_str(has_subklass()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
              layout_helper());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    _flags.print_klass_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    if (_super) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
      st->print(" super=");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
      _super->print_name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    if (_java_mirror) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
      st->print(" mirror=PRESENT");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
    st->print(" loaded=false");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
// ciInstanceKlass::super
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
// Get the superklass of this klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
ciInstanceKlass* ciInstanceKlass::super() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  assert(is_loaded(), "must be loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  if (_super == NULL && !is_java_lang_Object()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    GUARDED_VM_ENTRY(
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   329
      Klass* super_klass = get_instanceKlass()->super();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   330
      _super = CURRENT_ENV->get_instance_klass(super_klass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  return _super;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
// ciInstanceKlass::java_mirror
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
// 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
   340
// Cache it on this->_java_mirror.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
ciInstance* ciInstanceKlass::java_mirror() {
8725
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8314
diff changeset
   342
  if (is_shared()) {
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8314
diff changeset
   343
    return ciKlass::java_mirror();
8c1e3dd5fe1b 7017732: move static fields into Class to prepare for perm gen removal
never
parents: 8314
diff changeset
   344
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  if (_java_mirror == NULL) {
5884
3963019e3782 6960865: ldc of unloaded class throws an assert in ciTypeFlow
jrose
parents: 5882
diff changeset
   346
    _java_mirror = ciKlass::java_mirror();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
  return _java_mirror;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
// ciInstanceKlass::unique_concrete_subklass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
ciInstanceKlass* ciInstanceKlass::unique_concrete_subklass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  if (!is_loaded())     return NULL; // No change if class is not loaded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  if (!is_abstract())   return NULL; // Only applies to abstract classes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  if (!has_subklass())  return NULL; // Must have at least one subklass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  VM_ENTRY_MARK;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   358
  InstanceKlass* ik = get_instanceKlass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  Klass* up = ik->up_cast_abstract();
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 31519
diff changeset
   360
  assert(up->is_instance_klass(), "must be InstanceKlass");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  if (ik == up) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   364
  return CURRENT_THREAD_ENV->get_instance_klass(up);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
// ciInstanceKlass::has_finalizable_subclass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
bool ciInstanceKlass::has_finalizable_subclass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  if (!is_loaded())     return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  VM_ENTRY_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  return Dependencies::find_finalizable_subclass(get_instanceKlass()) != NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
// ciInstanceKlass::get_field_by_offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
ciField* ciInstanceKlass::get_field_by_offset(int field_offset, bool is_static) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  if (!is_static) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    for (int i = 0, len = nof_nonstatic_fields(); i < len; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
      ciField* field = _nonstatic_fields->at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
      int  field_off = field->offset_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
      if (field_off == field_offset)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
        return field;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
      if (field_off > field_offset)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
      // could do binary search or check bins, but probably not worth it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  VM_ENTRY_MARK;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   391
  InstanceKlass* k = get_instanceKlass();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  fieldDescriptor fd;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  if (!k->find_field_from_offset(field_offset, is_static, &fd)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
    return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  return field;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
217
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   400
// ------------------------------------------------------------------
4450
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   401
// ciInstanceKlass::get_field_by_name
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   402
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
   403
  VM_ENTRY_MARK;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   404
  InstanceKlass* k = get_instanceKlass();
4450
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   405
  fieldDescriptor fd;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   406
  Klass* def = k->find_field(name->get_symbol(), signature->get_symbol(), is_static, &fd);
4450
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   407
  if (def == NULL) {
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   408
    return NULL;
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   409
  }
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   410
  ciField* field = new (CURRENT_THREAD_ENV->arena()) ciField(&fd);
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   411
  return field;
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   412
}
6d700b859b3e 6892658: C2 should optimize some stringbuilder patterns
never
parents: 670
diff changeset
   413
217
c646ef2f5d58 6667620: (Escape Analysis) fix deoptimization for scalar replaced objects
kvn
parents: 1
diff changeset
   414
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
static int sort_field_by_offset(ciField** a, ciField** b) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  return (*a)->offset_in_bytes() - (*b)->offset_in_bytes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  // (no worries about 32-bit overflow...)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
// ciInstanceKlass::compute_nonstatic_fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
int ciInstanceKlass::compute_nonstatic_fields() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  assert(is_loaded(), "must be loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  if (_nonstatic_fields != NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
    return _nonstatic_fields->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   428
  if (!has_nonstatic_fields()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    Arena* arena = CURRENT_ENV->arena();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
    _nonstatic_fields = new (arena) GrowableArray<ciField*>(arena, 0, 0, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  assert(!is_java_lang_Object(), "bootstrap OK");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   435
  // 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
   436
  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
   437
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  ciInstanceKlass* super = this->super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  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
   440
  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
   441
    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
   442
    int super_flen   = super->nof_nonstatic_fields();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
    super_fields = super->_nonstatic_fields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
    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
   445
    // 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
   446
    if (fsize == super_fsize) {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   447
      _nonstatic_fields = super_fields;
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   448
      return super_fields->length();
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 217
diff changeset
   449
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  GrowableArray<ciField*>* fields = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  GUARDED_VM_ENTRY({
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
      fields = compute_nonstatic_fields_impl(super_fields);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    });
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  if (fields == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
    // This can happen if this class (java.lang.Class) has invisible fields.
31037
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 28933
diff changeset
   459
    if (super_fields != NULL) {
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 28933
diff changeset
   460
      _nonstatic_fields = super_fields;
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 28933
diff changeset
   461
      return super_fields->length();
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 28933
diff changeset
   462
    } else {
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 28933
diff changeset
   463
      return 0;
01a5c5fa5681 8079205: CallSite dependency tracking is broken after sun.misc.Cleaner became automatically cleared
vlivanov
parents: 28933
diff changeset
   464
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  int flen = fields->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  // Now sort them by offset, ascending.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  // (In principle, they could mix with superclass fields.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  fields->sort(sort_field_by_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  _nonstatic_fields = fields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  return flen;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
GrowableArray<ciField*>*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
ciInstanceKlass::compute_nonstatic_fields_impl(GrowableArray<ciField*>*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
                                               super_fields) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  ASSERT_IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  Arena* arena = CURRENT_ENV->arena();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
  int flen = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  GrowableArray<ciField*>* fields = NULL;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   483
  InstanceKlass* k = get_instanceKlass();
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   484
  for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   485
    if (fs.access_flags().is_static())  continue;
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   486
    flen += 1;
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   487
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   489
  // allocate the array:
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   490
  if (flen == 0) {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   491
    return NULL;  // return nothing if none are locally declared
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   492
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   493
  if (super_fields != NULL) {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   494
    flen += super_fields->length();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   495
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   496
  fields = new (arena) GrowableArray<ciField*>(arena, flen, 0, NULL);
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   497
  if (super_fields != NULL) {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   498
    fields->appendAll(super_fields);
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   499
  }
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   500
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   501
  for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   502
    if (fs.access_flags().is_static())  continue;
20017
81eba62e9048 8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents: 17383
diff changeset
   503
    fieldDescriptor& fd = fs.field_descriptor();
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   504
    ciField* field = new (arena) ciField(&fd);
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8725
diff changeset
   505
    fields->append(field);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  assert(fields->length() == flen, "sanity");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  return fields;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
28933
a11a29cf06d5 8071821: Assert failed in UnexpectedDeoptimizationTest.java
roland
parents: 28396
diff changeset
   511
bool ciInstanceKlass::compute_injected_fields_helper() {
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
   512
  ASSERT_IN_VM;
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
   513
  InstanceKlass* k = get_instanceKlass();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
   514
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
   515
  for (InternalFieldStream fs(k); !fs.done(); fs.next()) {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
   516
    if (fs.access_flags().is_static())  continue;
28933
a11a29cf06d5 8071821: Assert failed in UnexpectedDeoptimizationTest.java
roland
parents: 28396
diff changeset
   517
    return true;
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
   518
  }
28933
a11a29cf06d5 8071821: Assert failed in UnexpectedDeoptimizationTest.java
roland
parents: 28396
diff changeset
   519
  return false;
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
   520
}
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
   521
28933
a11a29cf06d5 8071821: Assert failed in UnexpectedDeoptimizationTest.java
roland
parents: 28396
diff changeset
   522
void ciInstanceKlass::compute_injected_fields() {
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
   523
  assert(is_loaded(), "must be loaded");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
   524
28933
a11a29cf06d5 8071821: Assert failed in UnexpectedDeoptimizationTest.java
roland
parents: 28396
diff changeset
   525
  int has_injected_fields = 0;
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
   526
  if (super() != NULL && super()->has_injected_fields()) {
28933
a11a29cf06d5 8071821: Assert failed in UnexpectedDeoptimizationTest.java
roland
parents: 28396
diff changeset
   527
    has_injected_fields = 1;
a11a29cf06d5 8071821: Assert failed in UnexpectedDeoptimizationTest.java
roland
parents: 28396
diff changeset
   528
  } else {
a11a29cf06d5 8071821: Assert failed in UnexpectedDeoptimizationTest.java
roland
parents: 28396
diff changeset
   529
    GUARDED_VM_ENTRY({
a11a29cf06d5 8071821: Assert failed in UnexpectedDeoptimizationTest.java
roland
parents: 28396
diff changeset
   530
        has_injected_fields = compute_injected_fields_helper() ? 1 : 0;
a11a29cf06d5 8071821: Assert failed in UnexpectedDeoptimizationTest.java
roland
parents: 28396
diff changeset
   531
      });
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
   532
  }
28933
a11a29cf06d5 8071821: Assert failed in UnexpectedDeoptimizationTest.java
roland
parents: 28396
diff changeset
   533
  // may be concurrently initialized for shared ciInstanceKlass objects
a11a29cf06d5 8071821: Assert failed in UnexpectedDeoptimizationTest.java
roland
parents: 28396
diff changeset
   534
  assert(_has_injected_fields == -1 || _has_injected_fields == has_injected_fields, "broken concurrent initialization");
a11a29cf06d5 8071821: Assert failed in UnexpectedDeoptimizationTest.java
roland
parents: 28396
diff changeset
   535
  _has_injected_fields = has_injected_fields;
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
   536
}
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents: 26706
diff changeset
   537
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
// ciInstanceKlass::find_method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
// Find a method in this klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
ciMethod* ciInstanceKlass::find_method(ciSymbol* name, ciSymbol* signature) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  VM_ENTRY_MARK;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   544
  InstanceKlass* k = get_instanceKlass();
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   545
  Symbol* name_sym = name->get_symbol();
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   546
  Symbol* sig_sym= signature->get_symbol();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   548
  Method* m = k->find_method(name_sym, sig_sym);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  if (m == NULL)  return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   551
  return CURRENT_THREAD_ENV->get_method(m);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
// ciInstanceKlass::is_leaf_type
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
bool ciInstanceKlass::is_leaf_type() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  assert(is_loaded(), "must be loaded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  if (is_shared()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
    return is_final();  // approximately correct
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  } else {
12369
48fd3da4025c 7154670: The instanceKlass _implementors[] and _nof_implementors are not needed for non-interface klass.
jiangli
parents: 11407
diff changeset
   561
    return !_has_subklass && (nof_implementors() == 0);
1
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
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
// ciInstanceKlass::implementor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
// Report an implementor of this interface.
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
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   571
// to results returned by InstanceKlass::implementor.
1
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.
12369
48fd3da4025c 7154670: The instanceKlass _implementors[] and _nof_implementors are not needed for non-interface klass.
jiangli
parents: 11407
diff changeset
   574
ciInstanceKlass* ciInstanceKlass::implementor() {
48fd3da4025c 7154670: The instanceKlass _implementors[] and _nof_implementors are not needed for non-interface klass.
jiangli
parents: 11407
diff changeset
   575
  ciInstanceKlass* impl = _implementor;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
  if (impl == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
    // Go into the VM to fetch the implementor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
      VM_ENTRY_MARK;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   580
      Klass* k = get_instanceKlass()->implementor();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
      if (k != NULL) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   582
        if (k == get_instanceKlass()) {
12369
48fd3da4025c 7154670: The instanceKlass _implementors[] and _nof_implementors are not needed for non-interface klass.
jiangli
parents: 11407
diff changeset
   583
          // More than one implementors. Use 'this' in this case.
48fd3da4025c 7154670: The instanceKlass _implementors[] and _nof_implementors are not needed for non-interface klass.
jiangli
parents: 11407
diff changeset
   584
          impl = this;
48fd3da4025c 7154670: The instanceKlass _implementors[] and _nof_implementors are not needed for non-interface klass.
jiangli
parents: 11407
diff changeset
   585
        } else {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 12369
diff changeset
   586
          impl = CURRENT_THREAD_ENV->get_instance_klass(k);
12369
48fd3da4025c 7154670: The instanceKlass _implementors[] and _nof_implementors are not needed for non-interface klass.
jiangli
parents: 11407
diff changeset
   587
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    // Memoize this result.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
    if (!is_shared()) {
12369
48fd3da4025c 7154670: The instanceKlass _implementors[] and _nof_implementors are not needed for non-interface klass.
jiangli
parents: 11407
diff changeset
   592
      _implementor = impl;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  return impl;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
}
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   597
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   598
// Utility class for printing of the contents of the static fields for
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   599
// use by compilation replay.  It only prints out the information that
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   600
// could be consumed by the compiler, so for primitive types it prints
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   601
// out the actual value.  For Strings it's the actual string value.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   602
// For array types it it's first level array size since that's the
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   603
// only value which statically unchangeable.  For all other reference
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   604
// types it simply prints out the dynamic type.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   605
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   606
class StaticFinalFieldPrinter : public FieldClosure {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   607
  outputStream* _out;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   608
  const char*   _holder;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   609
 public:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   610
  StaticFinalFieldPrinter(outputStream* out, const char* holder) :
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   611
    _out(out),
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   612
    _holder(holder) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   613
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   614
  void do_field(fieldDescriptor* fd) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   615
    if (fd->is_final() && !fd->has_initial_value()) {
15471
41f75023e6a6 8006410: allocating without ResourceMark when CompileCommand was specified
vlivanov
parents: 14477
diff changeset
   616
      ResourceMark rm;
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   617
      oop mirror = fd->field_holder()->java_mirror();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   618
      _out->print("staticfield %s %s %s ", _holder, fd->name()->as_quoted_ascii(), fd->signature()->as_quoted_ascii());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   619
      switch (fd->field_type()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   620
        case T_BYTE:    _out->print_cr("%d", mirror->byte_field(fd->offset()));   break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   621
        case T_BOOLEAN: _out->print_cr("%d", mirror->bool_field(fd->offset()));   break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   622
        case T_SHORT:   _out->print_cr("%d", mirror->short_field(fd->offset()));  break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   623
        case T_CHAR:    _out->print_cr("%d", mirror->char_field(fd->offset()));   break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   624
        case T_INT:     _out->print_cr("%d", mirror->int_field(fd->offset()));    break;
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 21209
diff changeset
   625
        case T_LONG:    _out->print_cr(INT64_FORMAT, (int64_t)(mirror->long_field(fd->offset())));   break;
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   626
        case T_FLOAT: {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   627
          float f = mirror->float_field(fd->offset());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   628
          _out->print_cr("%d", *(int*)&f);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   629
          break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   630
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   631
        case T_DOUBLE: {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   632
          double d = mirror->double_field(fd->offset());
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 21209
diff changeset
   633
          _out->print_cr(INT64_FORMAT, *(int64_t*)&d);
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   634
          break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   635
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   636
        case T_ARRAY: {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   637
          oop value =  mirror->obj_field_acquire(fd->offset());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   638
          if (value == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   639
            _out->print_cr("null");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   640
          } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   641
            typeArrayOop ta = (typeArrayOop)value;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   642
            _out->print("%d", ta->length());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   643
            if (value->is_objArray()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   644
              objArrayOop oa = (objArrayOop)value;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   645
              const char* klass_name  = value->klass()->name()->as_quoted_ascii();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   646
              _out->print(" %s", klass_name);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   647
            }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   648
            _out->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   649
          }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   650
          break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   651
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   652
        case T_OBJECT: {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   653
          oop value =  mirror->obj_field_acquire(fd->offset());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   654
          if (value == NULL) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   655
            _out->print_cr("null");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   656
          } else if (value->is_instance()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   657
            if (value->is_a(SystemDictionary::String_klass())) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   658
              _out->print("\"");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   659
              _out->print_raw(java_lang_String::as_quoted_ascii(value));
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   660
              _out->print_cr("\"");
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   661
            } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   662
              const char* klass_name  = value->klass()->name()->as_quoted_ascii();
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 21209
diff changeset
   663
              _out->print_cr("%s", klass_name);
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   664
            }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   665
          } else {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   666
            ShouldNotReachHere();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   667
          }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   668
          break;
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   669
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   670
        default:
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   671
          ShouldNotReachHere();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   672
        }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   673
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   674
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   675
};
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   676
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   677
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   678
void ciInstanceKlass::dump_replay_data(outputStream* out) {
15471
41f75023e6a6 8006410: allocating without ResourceMark when CompileCommand was specified
vlivanov
parents: 14477
diff changeset
   679
  ResourceMark rm;
41f75023e6a6 8006410: allocating without ResourceMark when CompileCommand was specified
vlivanov
parents: 14477
diff changeset
   680
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   681
  InstanceKlass* ik = get_instanceKlass();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   682
  ConstantPool*  cp = ik->constants();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   683
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   684
  // Try to record related loaded classes
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   685
  Klass* sub = ik->subklass();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   686
  while (sub != NULL) {
33611
9abd65805e19 8139203: Consistent naming for klass type predicates
coleenp
parents: 31519
diff changeset
   687
    if (sub->is_instance_klass()) {
14477
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   688
      out->print_cr("instanceKlass %s", sub->name()->as_quoted_ascii());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   689
    }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   690
    sub = sub->next_sibling();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   691
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   692
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   693
  // Dump out the state of the constant pool tags.  During replay the
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   694
  // tags will be validated for things which shouldn't change and
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   695
  // classes will be resolved if the tags indicate that they were
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   696
  // resolved at compile time.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   697
  out->print("ciInstanceKlass %s %d %d %d", ik->name()->as_quoted_ascii(),
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   698
             is_linked(), is_initialized(), cp->length());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   699
  for (int index = 1; index < cp->length(); index++) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   700
    out->print(" %d", cp->tags()->at(index));
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   701
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   702
  out->cr();
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   703
  if (is_initialized()) {
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   704
    //  Dump out the static final fields in case the compilation relies
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   705
    //  on their value for correct replay.
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   706
    StaticFinalFieldPrinter sffp(out, ik->name()->as_quoted_ascii());
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   707
    ik->do_local_static_fields(&sffp);
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   708
  }
95e66ea71f71 6830717: replay of compilations would help with debugging
minqi
parents: 13728
diff changeset
   709
}