hotspot/src/share/vm/oops/oop.cpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 360 21d113ecbf6a
permissions -rw-r--r--
Initial load
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 1997-2006 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/_oop.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
bool always_do_update_barrier = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
BarrierSet* oopDesc::_bs = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
#ifdef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
void oopDesc::print_on(outputStream* st) const {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
void oopDesc::print_value_on(outputStream* st) const {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
void oopDesc::print_address_on(outputStream* st) const {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
char* oopDesc::print_value_string() { return NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
char* oopDesc::print_string() { return NULL; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
void oopDesc::print()         {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
void oopDesc::print_value()   {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
void oopDesc::print_address() {}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
void oopDesc::print_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  if (this == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    st->print_cr("NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    blueprint()->oop_print_on(oop(this), st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
void oopDesc::print_value_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  oop obj = oop(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  if (this == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    st->print("NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  } else if (java_lang_String::is_instance(obj)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    java_lang_String::print(obj, st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    if (PrintOopAddress) print_address_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  } else if (!Universe::heap()->is_in(obj) || !Universe::heap()->is_in(klass())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    st->print("### BAD OOP %p ###", (address)obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    blueprint()->oop_print_value_on(obj, st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
void oopDesc::print_address_on(outputStream* st) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  if (PrintOopAddress) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    st->print("{");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    if (PrintOopAddress) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
      st->print(INTPTR_FORMAT, this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    st->print("}");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
void oopDesc::print()         { print_on(tty);         }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
void oopDesc::print_value()   { print_value_on(tty);   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
void oopDesc::print_address() { print_address_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
char* oopDesc::print_string() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  stringStream* st = new stringStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  print_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  return st->as_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
char* oopDesc::print_value_string() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  stringStream* st = new stringStream();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  print_value_on(st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  return st->as_string();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
void oopDesc::verify_on(outputStream* st) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  if (this != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    blueprint()->oop_verify_on(this, st);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
void oopDesc::verify() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  verify_on(tty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
void oopDesc::verify_old_oop(oop* p, bool allow_dirty) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  blueprint()->oop_verify_old_oop(this, p, allow_dirty);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
bool oopDesc::partially_loaded() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  return blueprint()->oop_partially_loaded(this);
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
void oopDesc::set_partially_loaded() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  blueprint()->oop_set_partially_loaded(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
intptr_t oopDesc::slow_identity_hash() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  // slow case; we have to acquire the micro lock in order to locate the header
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  ResetNoHandleMark rnm; // Might be called from LEAF/QUICK ENTRY
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  HandleMark hm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  Handle object((oop)this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  assert(!is_shared_readonly(), "using identity hash on readonly object?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  return ObjectSynchronizer::identity_hash_value_for(object);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
VerifyOopClosure VerifyOopClosure::verify_oop;