src/share/vm/runtime/interfaceSupport.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6680
78bbf4d43a14
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

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

mercurial