src/share/vm/runtime/interfaceSupport.cpp

Tue, 16 Feb 2010 16:17:46 -0800

author
kvn
date
Tue, 16 Feb 2010 16:17:46 -0800
changeset 1698
e7b1cc79bd25
parent 1279
bd02caa94611
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6926697: "optimized" VM build failed: The type "AdapterHandlerTableIterator" is incomplete
Summary: Define AdapterHandlerTableIterator class as non product instead of debug.
Reviewed-by: never

duke@435 1 /*
xdono@1279 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 #include "incls/_precompiled.incl"
duke@435 26 #include "incls/_interfaceSupport.cpp.incl"
duke@435 27
duke@435 28
duke@435 29 // Implementation of InterfaceSupport
duke@435 30
duke@435 31 #ifdef ASSERT
duke@435 32
duke@435 33 long InterfaceSupport::_number_of_calls = 0;
duke@435 34 long InterfaceSupport::_scavenge_alot_counter = 1;
duke@435 35 long InterfaceSupport::_fullgc_alot_counter = 1;
duke@435 36 long InterfaceSupport::_fullgc_alot_invocation = 0;
duke@435 37
duke@435 38 Histogram* RuntimeHistogram;
duke@435 39
duke@435 40 RuntimeHistogramElement::RuntimeHistogramElement(const char* elementName) {
duke@435 41 static volatile jint RuntimeHistogram_lock = 0;
duke@435 42 _name = elementName;
duke@435 43 uintx count = 0;
duke@435 44
duke@435 45 while (Atomic::cmpxchg(1, &RuntimeHistogram_lock, 0) != 0) {
duke@435 46 while (OrderAccess::load_acquire(&RuntimeHistogram_lock) != 0) {
duke@435 47 count +=1;
duke@435 48 if ( (WarnOnStalledSpinLock > 0)
duke@435 49 && (count % WarnOnStalledSpinLock == 0)) {
duke@435 50 warning("RuntimeHistogram_lock seems to be stalled");
duke@435 51 }
duke@435 52 }
duke@435 53 }
duke@435 54
duke@435 55 if (RuntimeHistogram == NULL) {
duke@435 56 RuntimeHistogram = new Histogram("VM Runtime Call Counts",200);
duke@435 57 }
duke@435 58
duke@435 59 RuntimeHistogram->add_element(this);
duke@435 60 Atomic::dec(&RuntimeHistogram_lock);
duke@435 61 }
duke@435 62
duke@435 63 void InterfaceSupport::trace(const char* result_type, const char* header) {
duke@435 64 tty->print_cr("%6d %s", _number_of_calls, header);
duke@435 65 }
duke@435 66
duke@435 67 void InterfaceSupport::gc_alot() {
duke@435 68 Thread *thread = Thread::current();
ysr@1241 69 if (!thread->is_Java_thread()) return; // Avoid concurrent calls
duke@435 70 // Check for new, not quite initialized thread. A thread in new mode cannot initiate a GC.
duke@435 71 JavaThread *current_thread = (JavaThread *)thread;
duke@435 72 if (current_thread->active_handles() == NULL) return;
duke@435 73
ysr@1241 74 // Short-circuit any possible re-entrant gc-a-lot attempt
ysr@1241 75 if (thread->skip_gcalot()) return;
ysr@1241 76
duke@435 77 if (is_init_completed()) {
duke@435 78
duke@435 79 if (++_fullgc_alot_invocation < FullGCALotStart) {
duke@435 80 return;
duke@435 81 }
duke@435 82
duke@435 83 // Use this line if you want to block at a specific point,
duke@435 84 // e.g. one number_of_calls/scavenge/gc before you got into problems
duke@435 85 if (FullGCALot) _fullgc_alot_counter--;
duke@435 86
duke@435 87 // Check if we should force a full gc
duke@435 88 if (_fullgc_alot_counter == 0) {
duke@435 89 // Release dummy so objects are forced to move
duke@435 90 if (!Universe::release_fullgc_alot_dummy()) {
duke@435 91 warning("FullGCALot: Unable to release more dummies at bottom of heap");
duke@435 92 }
duke@435 93 HandleMark hm(thread);
duke@435 94 Universe::heap()->collect(GCCause::_full_gc_alot);
duke@435 95 unsigned int invocations = Universe::heap()->total_full_collections();
duke@435 96 // Compute new interval
duke@435 97 if (FullGCALotInterval > 1) {
duke@435 98 _fullgc_alot_counter = 1+(long)((double)FullGCALotInterval*os::random()/(max_jint+1.0));
duke@435 99 if (PrintGCDetails && Verbose) {
duke@435 100 tty->print_cr("Full gc no: %u\tInterval: %d", invocations,
duke@435 101 _fullgc_alot_counter);
duke@435 102 }
duke@435 103 } else {
duke@435 104 _fullgc_alot_counter = 1;
duke@435 105 }
duke@435 106 // Print progress message
duke@435 107 if (invocations % 100 == 0) {
duke@435 108 if (PrintGCDetails && Verbose) tty->print_cr("Full gc no: %u", invocations);
duke@435 109 }
duke@435 110 } else {
duke@435 111 if (ScavengeALot) _scavenge_alot_counter--;
duke@435 112 // Check if we should force a scavenge
duke@435 113 if (_scavenge_alot_counter == 0) {
duke@435 114 HandleMark hm(thread);
duke@435 115 Universe::heap()->collect(GCCause::_scavenge_alot);
duke@435 116 unsigned int invocations = Universe::heap()->total_collections() - Universe::heap()->total_full_collections();
duke@435 117 // Compute new interval
duke@435 118 if (ScavengeALotInterval > 1) {
duke@435 119 _scavenge_alot_counter = 1+(long)((double)ScavengeALotInterval*os::random()/(max_jint+1.0));
duke@435 120 if (PrintGCDetails && Verbose) {
duke@435 121 tty->print_cr("Scavenge no: %u\tInterval: %d", invocations,
duke@435 122 _scavenge_alot_counter);
duke@435 123 }
duke@435 124 } else {
duke@435 125 _scavenge_alot_counter = 1;
duke@435 126 }
duke@435 127 // Print progress message
duke@435 128 if (invocations % 1000 == 0) {
duke@435 129 if (PrintGCDetails && Verbose) tty->print_cr("Scavenge no: %u", invocations);
duke@435 130 }
duke@435 131 }
duke@435 132 }
duke@435 133 }
duke@435 134 }
duke@435 135
duke@435 136
duke@435 137 vframe* vframe_array[50];
duke@435 138 int walk_stack_counter = 0;
duke@435 139
duke@435 140 void InterfaceSupport::walk_stack_from(vframe* start_vf) {
duke@435 141 // walk
duke@435 142 int i = 0;
duke@435 143 for (vframe* f = start_vf; f; f = f->sender() ) {
duke@435 144 if (i < 50) vframe_array[i++] = f;
duke@435 145 }
duke@435 146 }
duke@435 147
duke@435 148
duke@435 149 void InterfaceSupport::walk_stack() {
duke@435 150 JavaThread* thread = JavaThread::current();
duke@435 151 walk_stack_counter++;
duke@435 152 if (!thread->has_last_Java_frame()) return;
duke@435 153 ResourceMark rm(thread);
duke@435 154 RegisterMap reg_map(thread);
duke@435 155 walk_stack_from(thread->last_java_vframe(&reg_map));
duke@435 156 }
duke@435 157
duke@435 158
duke@435 159 # ifdef ENABLE_ZAP_DEAD_LOCALS
duke@435 160
duke@435 161 static int zap_traversals = 0;
duke@435 162
duke@435 163 void InterfaceSupport::zap_dead_locals_old() {
duke@435 164 JavaThread* thread = JavaThread::current();
duke@435 165 if (zap_traversals == -1) // edit constant for debugging
duke@435 166 warning("I am here");
duke@435 167 int zap_frame_count = 0; // count frames to help debugging
duke@435 168 for (StackFrameStream sfs(thread); !sfs.is_done(); sfs.next()) {
duke@435 169 sfs.current()->zap_dead_locals(thread, sfs.register_map());
duke@435 170 ++zap_frame_count;
duke@435 171 }
duke@435 172 ++zap_traversals;
duke@435 173 }
duke@435 174
duke@435 175 # endif
duke@435 176
duke@435 177
duke@435 178 int deoptimizeAllCounter = 0;
duke@435 179 int zombieAllCounter = 0;
duke@435 180
duke@435 181
duke@435 182 void InterfaceSupport::zombieAll() {
duke@435 183 if (is_init_completed() && zombieAllCounter > ZombieALotInterval) {
duke@435 184 zombieAllCounter = 0;
duke@435 185 VM_ZombieAll op;
duke@435 186 VMThread::execute(&op);
duke@435 187 } else {
duke@435 188 zombieAllCounter++;
duke@435 189 }
duke@435 190 }
duke@435 191
duke@435 192 void InterfaceSupport::deoptimizeAll() {
duke@435 193 if (is_init_completed() ) {
duke@435 194 if (DeoptimizeALot && deoptimizeAllCounter > DeoptimizeALotInterval) {
duke@435 195 deoptimizeAllCounter = 0;
duke@435 196 VM_DeoptimizeAll op;
duke@435 197 VMThread::execute(&op);
duke@435 198 } else if (DeoptimizeRandom && (deoptimizeAllCounter & 0x1f) == (os::random() & 0x1f)) {
duke@435 199 VM_DeoptimizeAll op;
duke@435 200 VMThread::execute(&op);
duke@435 201 }
duke@435 202 }
duke@435 203 deoptimizeAllCounter++;
duke@435 204 }
duke@435 205
duke@435 206
duke@435 207 void InterfaceSupport::stress_derived_pointers() {
duke@435 208 #ifdef COMPILER2
duke@435 209 JavaThread *thread = JavaThread::current();
duke@435 210 if (!is_init_completed()) return;
duke@435 211 ResourceMark rm(thread);
duke@435 212 bool found = false;
duke@435 213 for (StackFrameStream sfs(thread); !sfs.is_done() && !found; sfs.next()) {
duke@435 214 CodeBlob* cb = sfs.current()->cb();
duke@435 215 if (cb != NULL && cb->oop_maps() ) {
duke@435 216 // Find oopmap for current method
duke@435 217 OopMap* map = cb->oop_map_for_return_address(sfs.current()->pc());
duke@435 218 assert(map != NULL, "no oopmap found for pc");
duke@435 219 found = map->has_derived_pointer();
duke@435 220 }
duke@435 221 }
duke@435 222 if (found) {
duke@435 223 // $$$ Not sure what to do here.
duke@435 224 /*
duke@435 225 Scavenge::invoke(0);
duke@435 226 */
duke@435 227 }
duke@435 228 #endif
duke@435 229 }
duke@435 230
duke@435 231
duke@435 232 void InterfaceSupport::verify_stack() {
duke@435 233 JavaThread* thread = JavaThread::current();
duke@435 234 ResourceMark rm(thread);
duke@435 235 // disabled because it throws warnings that oop maps should only be accessed
duke@435 236 // in VM thread or during debugging
duke@435 237
duke@435 238 if (!thread->has_pending_exception()) {
duke@435 239 // verification does not work if there are pending exceptions
duke@435 240 StackFrameStream sfs(thread);
duke@435 241 CodeBlob* cb = sfs.current()->cb();
duke@435 242 // In case of exceptions we might not have a runtime_stub on
duke@435 243 // top of stack, hence, all callee-saved registers are not going
duke@435 244 // to be setup correctly, hence, we cannot do stack verify
duke@435 245 if (cb != NULL && !(cb->is_runtime_stub() || cb->is_uncommon_trap_stub())) return;
duke@435 246
duke@435 247 for (; !sfs.is_done(); sfs.next()) {
duke@435 248 sfs.current()->verify(sfs.register_map());
duke@435 249 }
duke@435 250 }
duke@435 251 }
duke@435 252
duke@435 253
duke@435 254 void InterfaceSupport::verify_last_frame() {
duke@435 255 JavaThread* thread = JavaThread::current();
duke@435 256 ResourceMark rm(thread);
duke@435 257 RegisterMap reg_map(thread);
duke@435 258 frame fr = thread->last_frame();
duke@435 259 fr.verify(&reg_map);
duke@435 260 }
duke@435 261
duke@435 262
duke@435 263 #endif // ASSERT
duke@435 264
duke@435 265
duke@435 266 void InterfaceSupport_init() {
duke@435 267 #ifdef ASSERT
duke@435 268 if (ScavengeALot || FullGCALot) {
duke@435 269 srand(ScavengeALotInterval * FullGCALotInterval);
duke@435 270 }
duke@435 271 #endif
duke@435 272 }

mercurial