src/share/vm/runtime/interfaceSupport.cpp

Sun, 03 Feb 2013 22:43:57 +0100

author
ewendeli
date
Sun, 03 Feb 2013 22:43:57 +0100
changeset 4703
b5cb079ecaa4
parent 2708
1d1603768966
child 6680
78bbf4d43a14
permissions
-rw-r--r--

Merge

duke@435 1 /*
trims@2708 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "gc_implementation/shared/markSweep.hpp"
stefank@2314 27 #include "gc_interface/collectedHeap.hpp"
stefank@2314 28 #include "gc_interface/collectedHeap.inline.hpp"
stefank@2314 29 #include "memory/genCollectedHeap.hpp"
stefank@2314 30 #include "memory/resourceArea.hpp"
stefank@2314 31 #include "runtime/init.hpp"
stefank@2314 32 #include "runtime/interfaceSupport.hpp"
stefank@2314 33 #include "runtime/threadLocalStorage.hpp"
stefank@2314 34 #include "runtime/vframe.hpp"
stefank@2314 35 #include "utilities/preserveException.hpp"
duke@435 36
duke@435 37
duke@435 38 // Implementation of InterfaceSupport
duke@435 39
duke@435 40 #ifdef ASSERT
duke@435 41
duke@435 42 long InterfaceSupport::_number_of_calls = 0;
duke@435 43 long InterfaceSupport::_scavenge_alot_counter = 1;
duke@435 44 long InterfaceSupport::_fullgc_alot_counter = 1;
duke@435 45 long InterfaceSupport::_fullgc_alot_invocation = 0;
duke@435 46
duke@435 47 Histogram* RuntimeHistogram;
duke@435 48
duke@435 49 RuntimeHistogramElement::RuntimeHistogramElement(const char* elementName) {
duke@435 50 static volatile jint RuntimeHistogram_lock = 0;
duke@435 51 _name = elementName;
duke@435 52 uintx count = 0;
duke@435 53
duke@435 54 while (Atomic::cmpxchg(1, &RuntimeHistogram_lock, 0) != 0) {
duke@435 55 while (OrderAccess::load_acquire(&RuntimeHistogram_lock) != 0) {
duke@435 56 count +=1;
duke@435 57 if ( (WarnOnStalledSpinLock > 0)
duke@435 58 && (count % WarnOnStalledSpinLock == 0)) {
duke@435 59 warning("RuntimeHistogram_lock seems to be stalled");
duke@435 60 }
duke@435 61 }
duke@435 62 }
duke@435 63
duke@435 64 if (RuntimeHistogram == NULL) {
duke@435 65 RuntimeHistogram = new Histogram("VM Runtime Call Counts",200);
duke@435 66 }
duke@435 67
duke@435 68 RuntimeHistogram->add_element(this);
duke@435 69 Atomic::dec(&RuntimeHistogram_lock);
duke@435 70 }
duke@435 71
duke@435 72 void InterfaceSupport::trace(const char* result_type, const char* header) {
duke@435 73 tty->print_cr("%6d %s", _number_of_calls, header);
duke@435 74 }
duke@435 75
duke@435 76 void InterfaceSupport::gc_alot() {
duke@435 77 Thread *thread = Thread::current();
ysr@1241 78 if (!thread->is_Java_thread()) return; // Avoid concurrent calls
duke@435 79 // Check for new, not quite initialized thread. A thread in new mode cannot initiate a GC.
duke@435 80 JavaThread *current_thread = (JavaThread *)thread;
duke@435 81 if (current_thread->active_handles() == NULL) return;
duke@435 82
ysr@1241 83 // Short-circuit any possible re-entrant gc-a-lot attempt
ysr@1241 84 if (thread->skip_gcalot()) return;
ysr@1241 85
duke@435 86 if (is_init_completed()) {
duke@435 87
duke@435 88 if (++_fullgc_alot_invocation < FullGCALotStart) {
duke@435 89 return;
duke@435 90 }
duke@435 91
duke@435 92 // Use this line if you want to block at a specific point,
duke@435 93 // e.g. one number_of_calls/scavenge/gc before you got into problems
duke@435 94 if (FullGCALot) _fullgc_alot_counter--;
duke@435 95
duke@435 96 // Check if we should force a full gc
duke@435 97 if (_fullgc_alot_counter == 0) {
duke@435 98 // Release dummy so objects are forced to move
duke@435 99 if (!Universe::release_fullgc_alot_dummy()) {
duke@435 100 warning("FullGCALot: Unable to release more dummies at bottom of heap");
duke@435 101 }
duke@435 102 HandleMark hm(thread);
duke@435 103 Universe::heap()->collect(GCCause::_full_gc_alot);
duke@435 104 unsigned int invocations = Universe::heap()->total_full_collections();
duke@435 105 // Compute new interval
duke@435 106 if (FullGCALotInterval > 1) {
duke@435 107 _fullgc_alot_counter = 1+(long)((double)FullGCALotInterval*os::random()/(max_jint+1.0));
duke@435 108 if (PrintGCDetails && Verbose) {
duke@435 109 tty->print_cr("Full gc no: %u\tInterval: %d", invocations,
duke@435 110 _fullgc_alot_counter);
duke@435 111 }
duke@435 112 } else {
duke@435 113 _fullgc_alot_counter = 1;
duke@435 114 }
duke@435 115 // Print progress message
duke@435 116 if (invocations % 100 == 0) {
duke@435 117 if (PrintGCDetails && Verbose) tty->print_cr("Full gc no: %u", invocations);
duke@435 118 }
duke@435 119 } else {
duke@435 120 if (ScavengeALot) _scavenge_alot_counter--;
duke@435 121 // Check if we should force a scavenge
duke@435 122 if (_scavenge_alot_counter == 0) {
duke@435 123 HandleMark hm(thread);
duke@435 124 Universe::heap()->collect(GCCause::_scavenge_alot);
duke@435 125 unsigned int invocations = Universe::heap()->total_collections() - Universe::heap()->total_full_collections();
duke@435 126 // Compute new interval
duke@435 127 if (ScavengeALotInterval > 1) {
duke@435 128 _scavenge_alot_counter = 1+(long)((double)ScavengeALotInterval*os::random()/(max_jint+1.0));
duke@435 129 if (PrintGCDetails && Verbose) {
duke@435 130 tty->print_cr("Scavenge no: %u\tInterval: %d", invocations,
duke@435 131 _scavenge_alot_counter);
duke@435 132 }
duke@435 133 } else {
duke@435 134 _scavenge_alot_counter = 1;
duke@435 135 }
duke@435 136 // Print progress message
duke@435 137 if (invocations % 1000 == 0) {
duke@435 138 if (PrintGCDetails && Verbose) tty->print_cr("Scavenge no: %u", invocations);
duke@435 139 }
duke@435 140 }
duke@435 141 }
duke@435 142 }
duke@435 143 }
duke@435 144
duke@435 145
duke@435 146 vframe* vframe_array[50];
duke@435 147 int walk_stack_counter = 0;
duke@435 148
duke@435 149 void InterfaceSupport::walk_stack_from(vframe* start_vf) {
duke@435 150 // walk
duke@435 151 int i = 0;
duke@435 152 for (vframe* f = start_vf; f; f = f->sender() ) {
duke@435 153 if (i < 50) vframe_array[i++] = f;
duke@435 154 }
duke@435 155 }
duke@435 156
duke@435 157
duke@435 158 void InterfaceSupport::walk_stack() {
duke@435 159 JavaThread* thread = JavaThread::current();
duke@435 160 walk_stack_counter++;
duke@435 161 if (!thread->has_last_Java_frame()) return;
duke@435 162 ResourceMark rm(thread);
duke@435 163 RegisterMap reg_map(thread);
duke@435 164 walk_stack_from(thread->last_java_vframe(&reg_map));
duke@435 165 }
duke@435 166
duke@435 167
duke@435 168 # ifdef ENABLE_ZAP_DEAD_LOCALS
duke@435 169
duke@435 170 static int zap_traversals = 0;
duke@435 171
duke@435 172 void InterfaceSupport::zap_dead_locals_old() {
duke@435 173 JavaThread* thread = JavaThread::current();
duke@435 174 if (zap_traversals == -1) // edit constant for debugging
duke@435 175 warning("I am here");
duke@435 176 int zap_frame_count = 0; // count frames to help debugging
duke@435 177 for (StackFrameStream sfs(thread); !sfs.is_done(); sfs.next()) {
duke@435 178 sfs.current()->zap_dead_locals(thread, sfs.register_map());
duke@435 179 ++zap_frame_count;
duke@435 180 }
duke@435 181 ++zap_traversals;
duke@435 182 }
duke@435 183
duke@435 184 # endif
duke@435 185
duke@435 186
duke@435 187 int deoptimizeAllCounter = 0;
duke@435 188 int zombieAllCounter = 0;
duke@435 189
duke@435 190
duke@435 191 void InterfaceSupport::zombieAll() {
duke@435 192 if (is_init_completed() && zombieAllCounter > ZombieALotInterval) {
duke@435 193 zombieAllCounter = 0;
duke@435 194 VM_ZombieAll op;
duke@435 195 VMThread::execute(&op);
duke@435 196 } else {
duke@435 197 zombieAllCounter++;
duke@435 198 }
duke@435 199 }
duke@435 200
coleenp@2497 201 void InterfaceSupport::unlinkSymbols() {
coleenp@2497 202 VM_UnlinkSymbols op;
coleenp@2497 203 VMThread::execute(&op);
coleenp@2497 204 }
coleenp@2497 205
duke@435 206 void InterfaceSupport::deoptimizeAll() {
duke@435 207 if (is_init_completed() ) {
duke@435 208 if (DeoptimizeALot && deoptimizeAllCounter > DeoptimizeALotInterval) {
duke@435 209 deoptimizeAllCounter = 0;
duke@435 210 VM_DeoptimizeAll op;
duke@435 211 VMThread::execute(&op);
duke@435 212 } else if (DeoptimizeRandom && (deoptimizeAllCounter & 0x1f) == (os::random() & 0x1f)) {
duke@435 213 VM_DeoptimizeAll op;
duke@435 214 VMThread::execute(&op);
duke@435 215 }
duke@435 216 }
duke@435 217 deoptimizeAllCounter++;
duke@435 218 }
duke@435 219
duke@435 220
duke@435 221 void InterfaceSupport::stress_derived_pointers() {
duke@435 222 #ifdef COMPILER2
duke@435 223 JavaThread *thread = JavaThread::current();
duke@435 224 if (!is_init_completed()) return;
duke@435 225 ResourceMark rm(thread);
duke@435 226 bool found = false;
duke@435 227 for (StackFrameStream sfs(thread); !sfs.is_done() && !found; sfs.next()) {
duke@435 228 CodeBlob* cb = sfs.current()->cb();
duke@435 229 if (cb != NULL && cb->oop_maps() ) {
duke@435 230 // Find oopmap for current method
duke@435 231 OopMap* map = cb->oop_map_for_return_address(sfs.current()->pc());
duke@435 232 assert(map != NULL, "no oopmap found for pc");
duke@435 233 found = map->has_derived_pointer();
duke@435 234 }
duke@435 235 }
duke@435 236 if (found) {
duke@435 237 // $$$ Not sure what to do here.
duke@435 238 /*
duke@435 239 Scavenge::invoke(0);
duke@435 240 */
duke@435 241 }
duke@435 242 #endif
duke@435 243 }
duke@435 244
duke@435 245
duke@435 246 void InterfaceSupport::verify_stack() {
duke@435 247 JavaThread* thread = JavaThread::current();
duke@435 248 ResourceMark rm(thread);
duke@435 249 // disabled because it throws warnings that oop maps should only be accessed
duke@435 250 // in VM thread or during debugging
duke@435 251
duke@435 252 if (!thread->has_pending_exception()) {
duke@435 253 // verification does not work if there are pending exceptions
duke@435 254 StackFrameStream sfs(thread);
duke@435 255 CodeBlob* cb = sfs.current()->cb();
duke@435 256 // In case of exceptions we might not have a runtime_stub on
duke@435 257 // top of stack, hence, all callee-saved registers are not going
duke@435 258 // to be setup correctly, hence, we cannot do stack verify
duke@435 259 if (cb != NULL && !(cb->is_runtime_stub() || cb->is_uncommon_trap_stub())) return;
duke@435 260
duke@435 261 for (; !sfs.is_done(); sfs.next()) {
duke@435 262 sfs.current()->verify(sfs.register_map());
duke@435 263 }
duke@435 264 }
duke@435 265 }
duke@435 266
duke@435 267
duke@435 268 void InterfaceSupport::verify_last_frame() {
duke@435 269 JavaThread* thread = JavaThread::current();
duke@435 270 ResourceMark rm(thread);
duke@435 271 RegisterMap reg_map(thread);
duke@435 272 frame fr = thread->last_frame();
duke@435 273 fr.verify(&reg_map);
duke@435 274 }
duke@435 275
duke@435 276
duke@435 277 #endif // ASSERT
duke@435 278
duke@435 279
duke@435 280 void InterfaceSupport_init() {
duke@435 281 #ifdef ASSERT
duke@435 282 if (ScavengeALot || FullGCALot) {
duke@435 283 srand(ScavengeALotInterval * FullGCALotInterval);
duke@435 284 }
duke@435 285 #endif
duke@435 286 }

mercurial