hotspot/src/share/vm/oops/cpCacheOop.cpp
author xdono
Wed, 02 Jul 2008 12:55:16 -0700
changeset 670 ddf3e9583f2f
parent 360 21d113ecbf6a
child 2570 ecc7862946d4
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
670
ddf3e9583f2f 6719955: Update copyright year
xdono
parents: 360
diff changeset
     2
 * Copyright 1998-2008 Sun Microsystems, Inc.  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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_cpCacheOop.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// Implememtation of ConstantPoolCacheEntry
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
void ConstantPoolCacheEntry::set_initial_state(int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  assert(0 <= index && index < 0x10000, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  _indices = index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
int ConstantPoolCacheEntry::as_flags(TosState state, bool is_final,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
                    bool is_vfinal, bool is_volatile,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
                    bool is_method_interface, bool is_method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  int f = state;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  assert( state < number_of_states, "Invalid state in as_flags");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  f <<= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  if (is_final) f |= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  f <<= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  if (is_vfinal) f |= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  f <<= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  if (is_volatile) f |= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  f <<= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  if (is_method_interface) f |= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  f <<= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  if (is_method) f |= 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  f <<= ConstantPoolCacheEntry::hotSwapBit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // Preserve existing flag bit values
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  int old_state = ((_flags >> tosBits) & 0x0F);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  assert(old_state == 0 || old_state == state,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
         "inconsistent cpCache flags state");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  return (_flags | f) ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
void ConstantPoolCacheEntry::set_bytecode_1(Bytecodes::Code code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // Read once.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  volatile Bytecodes::Code c = bytecode_1();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  assert(c == 0 || c == code || code == 0, "update must be consistent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // Need to flush pending stores here before bytecode is written.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  OrderAccess::release_store_ptr(&_indices, _indices | ((u_char)code << 16));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
void ConstantPoolCacheEntry::set_bytecode_2(Bytecodes::Code code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // Read once.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  volatile Bytecodes::Code c = bytecode_2();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  assert(c == 0 || c == code || code == 0, "update must be consistent");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // Need to flush pending stores here before bytecode is written.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  OrderAccess::release_store_ptr(&_indices, _indices | ((u_char)code << 24));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
// It is possible to have two different dummy methodOops created
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
// when the resolve code for invoke interface executes concurrently
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
// Hence the assertion below is weakened a bit for the invokeinterface
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
// case.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
bool ConstantPoolCacheEntry::same_methodOop(oop cur_f1, oop f1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  return (cur_f1 == f1 || ((methodOop)cur_f1)->name() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
         ((methodOop)f1)->name() || ((methodOop)cur_f1)->signature() ==
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
         ((methodOop)f1)->signature());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
// Note that concurrent update of both bytecodes can leave one of them
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
// reset to zero.  This is harmless; the interpreter will simply re-resolve
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
// the damaged entry.  More seriously, the memory synchronization is needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
// to flush other fields (f1, f2) completely to memory before the bytecodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
// are updated, lest other processors see a non-zero bytecode but zero f1/f2.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
void ConstantPoolCacheEntry::set_field(Bytecodes::Code get_code,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
                                       Bytecodes::Code put_code,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
                                       KlassHandle field_holder,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
                                       int orig_field_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
                                       int field_offset,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
                                       TosState field_type,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
                                       bool is_final,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
                                       bool is_volatile) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  set_f1(field_holder());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  set_f2(field_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // The field index is used by jvm/ti and is the index into fields() array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // in holder instanceKlass.  This is scaled by instanceKlass::next_offset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  assert((orig_field_index % instanceKlass::next_offset) == 0, "wierd index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  const int field_index = orig_field_index / instanceKlass::next_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  assert(field_index <= field_index_mask,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
         "field index does not fit in low flag bits");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  set_flags(as_flags(field_type, is_final, false, is_volatile, false, false) |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
            (field_index & field_index_mask));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  set_bytecode_1(get_code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  set_bytecode_2(put_code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  NOT_PRODUCT(verify(tty));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
int  ConstantPoolCacheEntry::field_index() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  return (_flags & field_index_mask) * instanceKlass::next_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
void ConstantPoolCacheEntry::set_method(Bytecodes::Code invoke_code,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
                                        methodHandle method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
                                        int vtable_index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  assert(method->interpreter_entry() != NULL, "should have been set at this point");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  assert(!method->is_obsolete(),  "attempt to write obsolete method to cpCache");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  bool change_to_virtual = (invoke_code == Bytecodes::_invokeinterface);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  int byte_no = -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  bool needs_vfinal_flag = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  switch (invoke_code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    case Bytecodes::_invokevirtual:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    case Bytecodes::_invokeinterface: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
        if (method->can_be_statically_bound()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
          set_f2((intptr_t)method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
          needs_vfinal_flag = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
          assert(vtable_index >= 0, "valid index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
          set_f2(vtable_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
        byte_no = 2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    case Bytecodes::_invokespecial:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      // Preserve the value of the vfinal flag on invokevirtual bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      // which may be shared with this constant pool cache entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      needs_vfinal_flag = is_resolved(Bytecodes::_invokevirtual) && is_vfinal();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    case Bytecodes::_invokestatic:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
      set_f1(method());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      byte_no = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  set_flags(as_flags(as_TosState(method->result_type()),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
                     method->is_final_method(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
                     needs_vfinal_flag,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
                     false,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
                     change_to_virtual,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
                     true)|
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
            method()->size_of_parameters());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // Note:  byte_no also appears in TemplateTable::resolve.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  if (byte_no == 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    set_bytecode_1(invoke_code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  } else if (byte_no == 2)  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    if (change_to_virtual) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      // NOTE: THIS IS A HACK - BE VERY CAREFUL!!!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
      // Workaround for the case where we encounter an invokeinterface, but we
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
      // should really have an _invokevirtual since the resolved method is a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      // virtual method in java.lang.Object. This is a corner case in the spec
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      // but is presumably legal. javac does not generate this code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
      //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      // We set bytecode_1() to _invokeinterface, because that is the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      // bytecode # used by the interpreter to see if it is resolved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      // We set bytecode_2() to _invokevirtual.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
      // See also interpreterRuntime.cpp. (8/25/2000)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
      // Only set resolved for the invokeinterface case if method is public.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
      // Otherwise, the method needs to be reresolved with caller for each
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      // interface call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      if (method->is_public()) set_bytecode_1(invoke_code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      set_bytecode_2(Bytecodes::_invokevirtual);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
      set_bytecode_2(invoke_code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
  NOT_PRODUCT(verify(tty));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
void ConstantPoolCacheEntry::set_interface_call(methodHandle method, int index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  klassOop interf = method->method_holder();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  assert(instanceKlass::cast(interf)->is_interface(), "must be an interface");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  set_f1(interf);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  set_f2(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  set_flags(as_flags(as_TosState(method->result_type()), method->is_final_method(), false, false, false, true) | method()->size_of_parameters());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  set_bytecode_1(Bytecodes::_invokeinterface);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
class LocalOopClosure: public OopClosure {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  void (*_f)(oop*);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  LocalOopClosure(void f(oop*))        { _f = f; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  virtual void do_oop(oop* o)          { _f(o); }
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
   221
  virtual void do_oop(narrowOop *o)    { ShouldNotReachHere(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
void ConstantPoolCacheEntry::oops_do(void f(oop*)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  LocalOopClosure blk(f);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  oop_iterate(&blk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
void ConstantPoolCacheEntry::oop_iterate(OopClosure* blk) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  assert(in_words(size()) == 4, "check code below - may need adjustment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  // field[1] is always oop or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  blk->do_oop((oop*)&_f1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  if (is_vfinal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    blk->do_oop((oop*)&_f2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
void ConstantPoolCacheEntry::oop_iterate_m(OopClosure* blk, MemRegion mr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  assert(in_words(size()) == 4, "check code below - may need adjustment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  // field[1] is always oop or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  if (mr.contains((oop *)&_f1)) blk->do_oop((oop*)&_f1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  if (is_vfinal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    if (mr.contains((oop *)&_f2)) blk->do_oop((oop*)&_f2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
void ConstantPoolCacheEntry::follow_contents() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  assert(in_words(size()) == 4, "check code below - may need adjustment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  // field[1] is always oop or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  MarkSweep::mark_and_push((oop*)&_f1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  if (is_vfinal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    MarkSweep::mark_and_push((oop*)&_f2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
void ConstantPoolCacheEntry::follow_contents(ParCompactionManager* cm) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  assert(in_words(size()) == 4, "check code below - may need adjustment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  // field[1] is always oop or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  PSParallelCompact::mark_and_push(cm, (oop*)&_f1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  if (is_vfinal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    PSParallelCompact::mark_and_push(cm, (oop*)&_f2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
void ConstantPoolCacheEntry::adjust_pointers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  assert(in_words(size()) == 4, "check code below - may need adjustment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  // field[1] is always oop or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  MarkSweep::adjust_pointer((oop*)&_f1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  if (is_vfinal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
    MarkSweep::adjust_pointer((oop*)&_f2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
#ifndef SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
void ConstantPoolCacheEntry::update_pointers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  assert(in_words(size()) == 4, "check code below - may need adjustment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  // field[1] is always oop or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  PSParallelCompact::adjust_pointer((oop*)&_f1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  if (is_vfinal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    PSParallelCompact::adjust_pointer((oop*)&_f2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
void ConstantPoolCacheEntry::update_pointers(HeapWord* beg_addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
                                             HeapWord* end_addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  assert(in_words(size()) == 4, "check code below - may need adjustment");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  // field[1] is always oop or NULL
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  PSParallelCompact::adjust_pointer((oop*)&_f1, beg_addr, end_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  if (is_vfinal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    PSParallelCompact::adjust_pointer((oop*)&_f2, beg_addr, end_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
#endif // SERIALGC
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
// RedefineClasses() API support:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
// If this constantPoolCacheEntry refers to old_method then update it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
// to refer to new_method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
bool ConstantPoolCacheEntry::adjust_method_entry(methodOop old_method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
       methodOop new_method, bool * trace_name_printed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  if (is_vfinal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    // virtual and final so f2() contains method ptr instead of vtable index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    if (f2() == (intptr_t)old_method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
      // match old_method so need an update
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
      _f2 = (intptr_t)new_method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
      if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
        if (!(*trace_name_printed)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
          // RC_TRACE_MESG macro has an embedded ResourceMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
          RC_TRACE_MESG(("adjust: name=%s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
            Klass::cast(old_method->method_holder())->external_name()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
          *trace_name_printed = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
        // RC_TRACE macro has an embedded ResourceMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
        RC_TRACE(0x00400000, ("cpc vf-entry update: %s(%s)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
          new_method->name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
          new_method->signature()->as_C_string()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
    // f1() is not used with virtual entries so bail out
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  if ((oop)_f1 == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    // NULL f1() means this is a virtual entry so bail out
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    // We are assuming that the vtable index does not need change.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  if ((oop)_f1 == old_method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    _f1 = new_method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    if (RC_TRACE_IN_RANGE(0x00100000, 0x00400000)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
      if (!(*trace_name_printed)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
        // RC_TRACE_MESG macro has an embedded ResourceMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
        RC_TRACE_MESG(("adjust: name=%s",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
          Klass::cast(old_method->method_holder())->external_name()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
        *trace_name_printed = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
      // RC_TRACE macro has an embedded ResourceMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
      RC_TRACE(0x00400000, ("cpc entry update: %s(%s)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
        new_method->name()->as_C_string(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
        new_method->signature()->as_C_string()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
bool ConstantPoolCacheEntry::is_interesting_method_entry(klassOop k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  if (!is_method_entry()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    // not a method entry so not interesting by default
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  methodOop m = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  if (is_vfinal()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    // virtual and final so _f2 contains method ptr instead of vtable index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
    m = (methodOop)_f2;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  } else if ((oop)_f1 == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
    // NULL _f1 means this is a virtual entry so also not interesting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    if (!((oop)_f1)->is_method()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
      // _f1 can also contain a klassOop for an interface
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
      return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    m = (methodOop)_f1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  assert(m != NULL && m->is_method(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  if (m == NULL || !m->is_method() || m->method_holder() != k) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
    // robustness for above sanity checks or method is not in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    // the interesting class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  // the method is in the interesting class so the entry is interesting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
void ConstantPoolCacheEntry::print(outputStream* st, int index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  // print separator
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  if (index == 0) tty->print_cr("                 -------------");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
  // print entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  tty->print_cr("%3d  (%08x)  [%02x|%02x|%5d]", index, this, bytecode_2(), bytecode_1(), constant_pool_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  tty->print_cr("                 [   %08x]", (address)(oop)_f1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  tty->print_cr("                 [   %08x]", _f2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  tty->print_cr("                 [   %08x]", _flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  tty->print_cr("                 -------------");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
void ConstantPoolCacheEntry::verify(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  // not implemented yet
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
// Implementation of ConstantPoolCache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
void constantPoolCacheOopDesc::initialize(intArray& inverse_index_map) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  assert(inverse_index_map.length() == length(), "inverse index map must have same length as cache");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  for (int i = 0; i < length(); i++) entry_at(i)->set_initial_state(inverse_index_map[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
// RedefineClasses() API support:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
// If any entry of this constantPoolCache points to any of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
// old_methods, replace it with the corresponding new_method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
void constantPoolCacheOopDesc::adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
                                                     int methods_length, bool * trace_name_printed) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  if (methods_length == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
    // nothing to do if there are no methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  // get shorthand for the interesting class
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  klassOop old_holder = old_methods[0]->method_holder();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  for (int i = 0; i < length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
    if (!entry_at(i)->is_interesting_method_entry(old_holder)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
      // skip uninteresting methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
      continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
    // The constantPoolCache contains entries for several different
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
    // things, but we only care about methods. In fact, we only care
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
    // about methods in the same class as the one that contains the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    // old_methods. At this point, we have an interesting entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    for (int j = 0; j < methods_length; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
      methodOop old_method = old_methods[j];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
      methodOop new_method = new_methods[j];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
      if (entry_at(i)->adjust_method_entry(old_method, new_method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
          trace_name_printed)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
        // current old_method matched this entry and we updated it so
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
        // break out and get to the next interesting entry if there one
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
}