src/share/vm/runtime/interfaceSupport.cpp

Thu, 12 Oct 2017 21:27:07 +0800

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

mercurial