hotspot/src/share/vm/ci/ciObject.cpp
author xlu
Mon, 06 Apr 2009 15:47:39 -0700
changeset 2526 39a58a50be35
parent 1 489c9b5090e2
child 3908 24b55ad4c228
permissions -rw-r--r--
6699669: Hotspot server leaves synchronized block with monitor in bad state Summary: Remove usage of _highest_lock field in Thread so that is_lock_owned won't depend on the correct update of that field. Reviewed-by: never, dice, acorn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_ciObject.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// ciObject
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// This class represents an oop in the HotSpot virtual machine.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// Its subclasses are structured in a hierarchy which mirrors
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// an aggregate of the VM's oop and klass hierarchies (see
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// oopHierarchy.hpp).  Each instance of ciObject holds a handle
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// to a corresponding oop on the VM side and provides routines
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// for accessing the information in its oop.  By using the ciObject
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// hierarchy for accessing oops in the VM, the compiler ensures
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// that it is safe with respect to garbage collection; that is,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// GC and compilation can proceed independently without
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// interference.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// Within the VM, the oop and klass hierarchies are separate.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// The compiler interface does not preserve this separation --
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// the distinction between `klassOop' and `Klass' are not
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// reflected in the interface and instead the Klass hierarchy
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// is directly modeled as the subclasses of ciKlass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// ciObject::ciObject
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
ciObject::ciObject(oop o) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  ASSERT_IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  if (ciObjectFactory::is_initialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    _handle = JNIHandles::make_local(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    _handle = JNIHandles::make_global(o);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  _klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  _ident = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
// ciObject::ciObject
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
ciObject::ciObject(Handle h) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  ASSERT_IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  if (ciObjectFactory::is_initialized()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    _handle = JNIHandles::make_local(h());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    _handle = JNIHandles::make_global(h);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  _klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  _ident = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
// ciObject::ciObject
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
// Unloaded klass/method variant.  `klass' is the klass of the unloaded
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
// klass/method, if that makes sense.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
ciObject::ciObject(ciKlass* klass) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  ASSERT_IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  assert(klass != NULL, "must supply klass");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  _handle = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  _klass = klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  _ident = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
// ciObject::ciObject
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
// NULL variant.  Used only by ciNullObject.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
ciObject::ciObject() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  ASSERT_IN_VM;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  _handle = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  _klass = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  _ident = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
// ciObject::klass
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
// Get the ciKlass of this ciObject.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
ciKlass* ciObject::klass() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  if (_klass == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    if (_handle == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      // When both _klass and _handle are NULL, we are dealing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      // with the distinguished instance of ciNullObject.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      // No one should ask it for its klass.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      assert(is_null_object(), "must be null object");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      return NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    GUARDED_VM_ENTRY(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      oop o = get_oop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      _klass = CURRENT_ENV->get_object(o->klass())->as_klass();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  return _klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
// ciObject::set_ident
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// Set the unique identity number of a ciObject.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
void ciObject::set_ident(uint id) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  assert((_ident >> FLAG_BITS) == 0, "must only initialize once");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  assert( id < ((uint)1 << (BitsPerInt-FLAG_BITS)), "id too big");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  _ident = _ident + (id << FLAG_BITS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
// ciObject::ident
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
// Report the unique identity number of a ciObject.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
uint ciObject::ident() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  uint id = _ident >> FLAG_BITS;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  assert(id != 0, "must be initialized");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  return id;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
// ciObject::equals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
// Are two ciObjects equal?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
bool ciObject::equals(ciObject* obj) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  return (this == obj);
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
// ciObject::hash
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
// A hash value for the convenience of compilers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
// Implementation note: we use the address of the ciObject as the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
// basis for the hash.  Use the _ident field, which is well-behaved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
int ciObject::hash() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  return ident() * 31;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
// ciObject::encoding
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
// The address which the compiler should embed into the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
// generated code to represent this oop.  This address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
// is not the true address of the oop -- it will get patched
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
// during nmethod creation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
// Implementation note: we use the handle as the encoding.  The
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
// nmethod constructor resolves the handle and patches in the oop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
// This method should be changed to return an generified address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
// to discourage use of the JNI handle.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
jobject ciObject::encoding() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  assert(is_null_object() || handle() != NULL, "cannot embed null pointer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  assert(has_encoding(), "oop must be NULL or perm");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  return handle();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
// ciObject::has_encoding
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
bool ciObject::has_encoding() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  return handle() == NULL || is_perm();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
// ------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
// ciObject::print
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
// Print debugging output about this ciObject.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
// Implementation note: dispatch to the virtual print_impl behavior
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
// for this ciObject.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
void ciObject::print(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  st->print("<%s", type_string());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  GUARDED_VM_ENTRY(print_impl(st);)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  st->print(" ident=%d %s address=0x%x>", ident(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
        is_perm() ? "PERM" : "",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
        (address)this);
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
// ciObject::print_oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
// Print debugging output about the oop this ciObject represents.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
void ciObject::print_oop(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  if (is_null_object()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    st->print_cr("NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  } else if (!is_loaded()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    st->print_cr("UNLOADED");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
    GUARDED_VM_ENTRY(get_oop()->print_on(st);)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
}