1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/interfaceSupport.cpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,287 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "precompiled.hpp" 1.29 +#include "gc_implementation/shared/markSweep.hpp" 1.30 +#include "gc_interface/collectedHeap.hpp" 1.31 +#include "gc_interface/collectedHeap.inline.hpp" 1.32 +#include "memory/genCollectedHeap.hpp" 1.33 +#include "memory/resourceArea.hpp" 1.34 +#include "runtime/init.hpp" 1.35 +#include "runtime/interfaceSupport.hpp" 1.36 +#include "runtime/threadLocalStorage.hpp" 1.37 +#include "runtime/vframe.hpp" 1.38 +#include "utilities/preserveException.hpp" 1.39 + 1.40 +PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC 1.41 + 1.42 +// Implementation of InterfaceSupport 1.43 + 1.44 +#ifdef ASSERT 1.45 + 1.46 +long InterfaceSupport::_number_of_calls = 0; 1.47 +long InterfaceSupport::_scavenge_alot_counter = 1; 1.48 +long InterfaceSupport::_fullgc_alot_counter = 1; 1.49 +long InterfaceSupport::_fullgc_alot_invocation = 0; 1.50 + 1.51 +Histogram* RuntimeHistogram; 1.52 + 1.53 +RuntimeHistogramElement::RuntimeHistogramElement(const char* elementName) { 1.54 + static volatile jint RuntimeHistogram_lock = 0; 1.55 + _name = elementName; 1.56 + uintx count = 0; 1.57 + 1.58 + while (Atomic::cmpxchg(1, &RuntimeHistogram_lock, 0) != 0) { 1.59 + while (OrderAccess::load_acquire(&RuntimeHistogram_lock) != 0) { 1.60 + count +=1; 1.61 + if ( (WarnOnStalledSpinLock > 0) 1.62 + && (count % WarnOnStalledSpinLock == 0)) { 1.63 + warning("RuntimeHistogram_lock seems to be stalled"); 1.64 + } 1.65 + } 1.66 + } 1.67 + 1.68 + if (RuntimeHistogram == NULL) { 1.69 + RuntimeHistogram = new Histogram("VM Runtime Call Counts",200); 1.70 + } 1.71 + 1.72 + RuntimeHistogram->add_element(this); 1.73 + Atomic::dec(&RuntimeHistogram_lock); 1.74 +} 1.75 + 1.76 +void InterfaceSupport::trace(const char* result_type, const char* header) { 1.77 + tty->print_cr("%6d %s", _number_of_calls, header); 1.78 +} 1.79 + 1.80 +void InterfaceSupport::gc_alot() { 1.81 + Thread *thread = Thread::current(); 1.82 + if (!thread->is_Java_thread()) return; // Avoid concurrent calls 1.83 + // Check for new, not quite initialized thread. A thread in new mode cannot initiate a GC. 1.84 + JavaThread *current_thread = (JavaThread *)thread; 1.85 + if (current_thread->active_handles() == NULL) return; 1.86 + 1.87 + // Short-circuit any possible re-entrant gc-a-lot attempt 1.88 + if (thread->skip_gcalot()) return; 1.89 + 1.90 + if (is_init_completed()) { 1.91 + 1.92 + if (++_fullgc_alot_invocation < FullGCALotStart) { 1.93 + return; 1.94 + } 1.95 + 1.96 + // Use this line if you want to block at a specific point, 1.97 + // e.g. one number_of_calls/scavenge/gc before you got into problems 1.98 + if (FullGCALot) _fullgc_alot_counter--; 1.99 + 1.100 + // Check if we should force a full gc 1.101 + if (_fullgc_alot_counter == 0) { 1.102 + // Release dummy so objects are forced to move 1.103 + if (!Universe::release_fullgc_alot_dummy()) { 1.104 + warning("FullGCALot: Unable to release more dummies at bottom of heap"); 1.105 + } 1.106 + HandleMark hm(thread); 1.107 + Universe::heap()->collect(GCCause::_full_gc_alot); 1.108 + unsigned int invocations = Universe::heap()->total_full_collections(); 1.109 + // Compute new interval 1.110 + if (FullGCALotInterval > 1) { 1.111 + _fullgc_alot_counter = 1+(long)((double)FullGCALotInterval*os::random()/(max_jint+1.0)); 1.112 + if (PrintGCDetails && Verbose) { 1.113 + tty->print_cr("Full gc no: %u\tInterval: %d", invocations, 1.114 + _fullgc_alot_counter); 1.115 + } 1.116 + } else { 1.117 + _fullgc_alot_counter = 1; 1.118 + } 1.119 + // Print progress message 1.120 + if (invocations % 100 == 0) { 1.121 + if (PrintGCDetails && Verbose) tty->print_cr("Full gc no: %u", invocations); 1.122 + } 1.123 + } else { 1.124 + if (ScavengeALot) _scavenge_alot_counter--; 1.125 + // Check if we should force a scavenge 1.126 + if (_scavenge_alot_counter == 0) { 1.127 + HandleMark hm(thread); 1.128 + Universe::heap()->collect(GCCause::_scavenge_alot); 1.129 + unsigned int invocations = Universe::heap()->total_collections() - Universe::heap()->total_full_collections(); 1.130 + // Compute new interval 1.131 + if (ScavengeALotInterval > 1) { 1.132 + _scavenge_alot_counter = 1+(long)((double)ScavengeALotInterval*os::random()/(max_jint+1.0)); 1.133 + if (PrintGCDetails && Verbose) { 1.134 + tty->print_cr("Scavenge no: %u\tInterval: %d", invocations, 1.135 + _scavenge_alot_counter); 1.136 + } 1.137 + } else { 1.138 + _scavenge_alot_counter = 1; 1.139 + } 1.140 + // Print progress message 1.141 + if (invocations % 1000 == 0) { 1.142 + if (PrintGCDetails && Verbose) tty->print_cr("Scavenge no: %u", invocations); 1.143 + } 1.144 + } 1.145 + } 1.146 + } 1.147 +} 1.148 + 1.149 + 1.150 +vframe* vframe_array[50]; 1.151 +int walk_stack_counter = 0; 1.152 + 1.153 +void InterfaceSupport::walk_stack_from(vframe* start_vf) { 1.154 + // walk 1.155 + int i = 0; 1.156 + for (vframe* f = start_vf; f; f = f->sender() ) { 1.157 + if (i < 50) vframe_array[i++] = f; 1.158 + } 1.159 +} 1.160 + 1.161 + 1.162 +void InterfaceSupport::walk_stack() { 1.163 + JavaThread* thread = JavaThread::current(); 1.164 + walk_stack_counter++; 1.165 + if (!thread->has_last_Java_frame()) return; 1.166 + ResourceMark rm(thread); 1.167 + RegisterMap reg_map(thread); 1.168 + walk_stack_from(thread->last_java_vframe(®_map)); 1.169 +} 1.170 + 1.171 + 1.172 +# ifdef ENABLE_ZAP_DEAD_LOCALS 1.173 + 1.174 +static int zap_traversals = 0; 1.175 + 1.176 +void InterfaceSupport::zap_dead_locals_old() { 1.177 + JavaThread* thread = JavaThread::current(); 1.178 + if (zap_traversals == -1) // edit constant for debugging 1.179 + warning("I am here"); 1.180 + int zap_frame_count = 0; // count frames to help debugging 1.181 + for (StackFrameStream sfs(thread); !sfs.is_done(); sfs.next()) { 1.182 + sfs.current()->zap_dead_locals(thread, sfs.register_map()); 1.183 + ++zap_frame_count; 1.184 + } 1.185 + ++zap_traversals; 1.186 +} 1.187 + 1.188 +# endif 1.189 + 1.190 + 1.191 +int deoptimizeAllCounter = 0; 1.192 +int zombieAllCounter = 0; 1.193 + 1.194 + 1.195 +void InterfaceSupport::zombieAll() { 1.196 + if (is_init_completed() && zombieAllCounter > ZombieALotInterval) { 1.197 + zombieAllCounter = 0; 1.198 + VM_ZombieAll op; 1.199 + VMThread::execute(&op); 1.200 + } else { 1.201 + zombieAllCounter++; 1.202 + } 1.203 +} 1.204 + 1.205 +void InterfaceSupport::unlinkSymbols() { 1.206 + VM_UnlinkSymbols op; 1.207 + VMThread::execute(&op); 1.208 +} 1.209 + 1.210 +void InterfaceSupport::deoptimizeAll() { 1.211 + if (is_init_completed() ) { 1.212 + if (DeoptimizeALot && deoptimizeAllCounter > DeoptimizeALotInterval) { 1.213 + deoptimizeAllCounter = 0; 1.214 + VM_DeoptimizeAll op; 1.215 + VMThread::execute(&op); 1.216 + } else if (DeoptimizeRandom && (deoptimizeAllCounter & 0x1f) == (os::random() & 0x1f)) { 1.217 + VM_DeoptimizeAll op; 1.218 + VMThread::execute(&op); 1.219 + } 1.220 + } 1.221 + deoptimizeAllCounter++; 1.222 +} 1.223 + 1.224 + 1.225 +void InterfaceSupport::stress_derived_pointers() { 1.226 +#ifdef COMPILER2 1.227 + JavaThread *thread = JavaThread::current(); 1.228 + if (!is_init_completed()) return; 1.229 + ResourceMark rm(thread); 1.230 + bool found = false; 1.231 + for (StackFrameStream sfs(thread); !sfs.is_done() && !found; sfs.next()) { 1.232 + CodeBlob* cb = sfs.current()->cb(); 1.233 + if (cb != NULL && cb->oop_maps() ) { 1.234 + // Find oopmap for current method 1.235 + OopMap* map = cb->oop_map_for_return_address(sfs.current()->pc()); 1.236 + assert(map != NULL, "no oopmap found for pc"); 1.237 + found = map->has_derived_pointer(); 1.238 + } 1.239 + } 1.240 + if (found) { 1.241 + // $$$ Not sure what to do here. 1.242 + /* 1.243 + Scavenge::invoke(0); 1.244 + */ 1.245 + } 1.246 +#endif 1.247 +} 1.248 + 1.249 + 1.250 +void InterfaceSupport::verify_stack() { 1.251 + JavaThread* thread = JavaThread::current(); 1.252 + ResourceMark rm(thread); 1.253 + // disabled because it throws warnings that oop maps should only be accessed 1.254 + // in VM thread or during debugging 1.255 + 1.256 + if (!thread->has_pending_exception()) { 1.257 + // verification does not work if there are pending exceptions 1.258 + StackFrameStream sfs(thread); 1.259 + CodeBlob* cb = sfs.current()->cb(); 1.260 + // In case of exceptions we might not have a runtime_stub on 1.261 + // top of stack, hence, all callee-saved registers are not going 1.262 + // to be setup correctly, hence, we cannot do stack verify 1.263 + if (cb != NULL && !(cb->is_runtime_stub() || cb->is_uncommon_trap_stub())) return; 1.264 + 1.265 + for (; !sfs.is_done(); sfs.next()) { 1.266 + sfs.current()->verify(sfs.register_map()); 1.267 + } 1.268 + } 1.269 +} 1.270 + 1.271 + 1.272 +void InterfaceSupport::verify_last_frame() { 1.273 + JavaThread* thread = JavaThread::current(); 1.274 + ResourceMark rm(thread); 1.275 + RegisterMap reg_map(thread); 1.276 + frame fr = thread->last_frame(); 1.277 + fr.verify(®_map); 1.278 +} 1.279 + 1.280 + 1.281 +#endif // ASSERT 1.282 + 1.283 + 1.284 +void InterfaceSupport_init() { 1.285 +#ifdef ASSERT 1.286 + if (ScavengeALot || FullGCALot) { 1.287 + srand(ScavengeALotInterval * FullGCALotInterval); 1.288 + } 1.289 +#endif 1.290 +}