1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/interfaceSupport.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,269 @@ 1.4 +/* 1.5 + * Copyright 1997-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "incls/_precompiled.incl" 1.29 +#include "incls/_interfaceSupport.cpp.incl" 1.30 + 1.31 + 1.32 +// Implementation of InterfaceSupport 1.33 + 1.34 +#ifdef ASSERT 1.35 + 1.36 +long InterfaceSupport::_number_of_calls = 0; 1.37 +long InterfaceSupport::_scavenge_alot_counter = 1; 1.38 +long InterfaceSupport::_fullgc_alot_counter = 1; 1.39 +long InterfaceSupport::_fullgc_alot_invocation = 0; 1.40 + 1.41 +Histogram* RuntimeHistogram; 1.42 + 1.43 +RuntimeHistogramElement::RuntimeHistogramElement(const char* elementName) { 1.44 + static volatile jint RuntimeHistogram_lock = 0; 1.45 + _name = elementName; 1.46 + uintx count = 0; 1.47 + 1.48 + while (Atomic::cmpxchg(1, &RuntimeHistogram_lock, 0) != 0) { 1.49 + while (OrderAccess::load_acquire(&RuntimeHistogram_lock) != 0) { 1.50 + count +=1; 1.51 + if ( (WarnOnStalledSpinLock > 0) 1.52 + && (count % WarnOnStalledSpinLock == 0)) { 1.53 + warning("RuntimeHistogram_lock seems to be stalled"); 1.54 + } 1.55 + } 1.56 + } 1.57 + 1.58 + if (RuntimeHistogram == NULL) { 1.59 + RuntimeHistogram = new Histogram("VM Runtime Call Counts",200); 1.60 + } 1.61 + 1.62 + RuntimeHistogram->add_element(this); 1.63 + Atomic::dec(&RuntimeHistogram_lock); 1.64 +} 1.65 + 1.66 +void InterfaceSupport::trace(const char* result_type, const char* header) { 1.67 + tty->print_cr("%6d %s", _number_of_calls, header); 1.68 +} 1.69 + 1.70 +void InterfaceSupport::gc_alot() { 1.71 + Thread *thread = Thread::current(); 1.72 + if (thread->is_VM_thread()) return; // Avoid concurrent calls 1.73 + // Check for new, not quite initialized thread. A thread in new mode cannot initiate a GC. 1.74 + JavaThread *current_thread = (JavaThread *)thread; 1.75 + if (current_thread->active_handles() == NULL) return; 1.76 + 1.77 + if (is_init_completed()) { 1.78 + 1.79 + if (++_fullgc_alot_invocation < FullGCALotStart) { 1.80 + return; 1.81 + } 1.82 + 1.83 + // Use this line if you want to block at a specific point, 1.84 + // e.g. one number_of_calls/scavenge/gc before you got into problems 1.85 + if (FullGCALot) _fullgc_alot_counter--; 1.86 + 1.87 + // Check if we should force a full gc 1.88 + if (_fullgc_alot_counter == 0) { 1.89 + // Release dummy so objects are forced to move 1.90 + if (!Universe::release_fullgc_alot_dummy()) { 1.91 + warning("FullGCALot: Unable to release more dummies at bottom of heap"); 1.92 + } 1.93 + HandleMark hm(thread); 1.94 + Universe::heap()->collect(GCCause::_full_gc_alot); 1.95 + unsigned int invocations = Universe::heap()->total_full_collections(); 1.96 + // Compute new interval 1.97 + if (FullGCALotInterval > 1) { 1.98 + _fullgc_alot_counter = 1+(long)((double)FullGCALotInterval*os::random()/(max_jint+1.0)); 1.99 + if (PrintGCDetails && Verbose) { 1.100 + tty->print_cr("Full gc no: %u\tInterval: %d", invocations, 1.101 + _fullgc_alot_counter); 1.102 + } 1.103 + } else { 1.104 + _fullgc_alot_counter = 1; 1.105 + } 1.106 + // Print progress message 1.107 + if (invocations % 100 == 0) { 1.108 + if (PrintGCDetails && Verbose) tty->print_cr("Full gc no: %u", invocations); 1.109 + } 1.110 + } else { 1.111 + if (ScavengeALot) _scavenge_alot_counter--; 1.112 + // Check if we should force a scavenge 1.113 + if (_scavenge_alot_counter == 0) { 1.114 + HandleMark hm(thread); 1.115 + Universe::heap()->collect(GCCause::_scavenge_alot); 1.116 + unsigned int invocations = Universe::heap()->total_collections() - Universe::heap()->total_full_collections(); 1.117 + // Compute new interval 1.118 + if (ScavengeALotInterval > 1) { 1.119 + _scavenge_alot_counter = 1+(long)((double)ScavengeALotInterval*os::random()/(max_jint+1.0)); 1.120 + if (PrintGCDetails && Verbose) { 1.121 + tty->print_cr("Scavenge no: %u\tInterval: %d", invocations, 1.122 + _scavenge_alot_counter); 1.123 + } 1.124 + } else { 1.125 + _scavenge_alot_counter = 1; 1.126 + } 1.127 + // Print progress message 1.128 + if (invocations % 1000 == 0) { 1.129 + if (PrintGCDetails && Verbose) tty->print_cr("Scavenge no: %u", invocations); 1.130 + } 1.131 + } 1.132 + } 1.133 + } 1.134 +} 1.135 + 1.136 + 1.137 +vframe* vframe_array[50]; 1.138 +int walk_stack_counter = 0; 1.139 + 1.140 +void InterfaceSupport::walk_stack_from(vframe* start_vf) { 1.141 + // walk 1.142 + int i = 0; 1.143 + for (vframe* f = start_vf; f; f = f->sender() ) { 1.144 + if (i < 50) vframe_array[i++] = f; 1.145 + } 1.146 +} 1.147 + 1.148 + 1.149 +void InterfaceSupport::walk_stack() { 1.150 + JavaThread* thread = JavaThread::current(); 1.151 + walk_stack_counter++; 1.152 + if (!thread->has_last_Java_frame()) return; 1.153 + ResourceMark rm(thread); 1.154 + RegisterMap reg_map(thread); 1.155 + walk_stack_from(thread->last_java_vframe(®_map)); 1.156 +} 1.157 + 1.158 + 1.159 +# ifdef ENABLE_ZAP_DEAD_LOCALS 1.160 + 1.161 +static int zap_traversals = 0; 1.162 + 1.163 +void InterfaceSupport::zap_dead_locals_old() { 1.164 + JavaThread* thread = JavaThread::current(); 1.165 + if (zap_traversals == -1) // edit constant for debugging 1.166 + warning("I am here"); 1.167 + int zap_frame_count = 0; // count frames to help debugging 1.168 + for (StackFrameStream sfs(thread); !sfs.is_done(); sfs.next()) { 1.169 + sfs.current()->zap_dead_locals(thread, sfs.register_map()); 1.170 + ++zap_frame_count; 1.171 + } 1.172 + ++zap_traversals; 1.173 +} 1.174 + 1.175 +# endif 1.176 + 1.177 + 1.178 +int deoptimizeAllCounter = 0; 1.179 +int zombieAllCounter = 0; 1.180 + 1.181 + 1.182 +void InterfaceSupport::zombieAll() { 1.183 + if (is_init_completed() && zombieAllCounter > ZombieALotInterval) { 1.184 + zombieAllCounter = 0; 1.185 + VM_ZombieAll op; 1.186 + VMThread::execute(&op); 1.187 + } else { 1.188 + zombieAllCounter++; 1.189 + } 1.190 +} 1.191 + 1.192 +void InterfaceSupport::deoptimizeAll() { 1.193 + if (is_init_completed() ) { 1.194 + if (DeoptimizeALot && deoptimizeAllCounter > DeoptimizeALotInterval) { 1.195 + deoptimizeAllCounter = 0; 1.196 + VM_DeoptimizeAll op; 1.197 + VMThread::execute(&op); 1.198 + } else if (DeoptimizeRandom && (deoptimizeAllCounter & 0x1f) == (os::random() & 0x1f)) { 1.199 + VM_DeoptimizeAll op; 1.200 + VMThread::execute(&op); 1.201 + } 1.202 + } 1.203 + deoptimizeAllCounter++; 1.204 +} 1.205 + 1.206 + 1.207 +void InterfaceSupport::stress_derived_pointers() { 1.208 +#ifdef COMPILER2 1.209 + JavaThread *thread = JavaThread::current(); 1.210 + if (!is_init_completed()) return; 1.211 + ResourceMark rm(thread); 1.212 + bool found = false; 1.213 + for (StackFrameStream sfs(thread); !sfs.is_done() && !found; sfs.next()) { 1.214 + CodeBlob* cb = sfs.current()->cb(); 1.215 + if (cb != NULL && cb->oop_maps() ) { 1.216 + // Find oopmap for current method 1.217 + OopMap* map = cb->oop_map_for_return_address(sfs.current()->pc()); 1.218 + assert(map != NULL, "no oopmap found for pc"); 1.219 + found = map->has_derived_pointer(); 1.220 + } 1.221 + } 1.222 + if (found) { 1.223 + // $$$ Not sure what to do here. 1.224 + /* 1.225 + Scavenge::invoke(0); 1.226 + */ 1.227 + } 1.228 +#endif 1.229 +} 1.230 + 1.231 + 1.232 +void InterfaceSupport::verify_stack() { 1.233 + JavaThread* thread = JavaThread::current(); 1.234 + ResourceMark rm(thread); 1.235 + // disabled because it throws warnings that oop maps should only be accessed 1.236 + // in VM thread or during debugging 1.237 + 1.238 + if (!thread->has_pending_exception()) { 1.239 + // verification does not work if there are pending exceptions 1.240 + StackFrameStream sfs(thread); 1.241 + CodeBlob* cb = sfs.current()->cb(); 1.242 + // In case of exceptions we might not have a runtime_stub on 1.243 + // top of stack, hence, all callee-saved registers are not going 1.244 + // to be setup correctly, hence, we cannot do stack verify 1.245 + if (cb != NULL && !(cb->is_runtime_stub() || cb->is_uncommon_trap_stub())) return; 1.246 + 1.247 + for (; !sfs.is_done(); sfs.next()) { 1.248 + sfs.current()->verify(sfs.register_map()); 1.249 + } 1.250 + } 1.251 +} 1.252 + 1.253 + 1.254 +void InterfaceSupport::verify_last_frame() { 1.255 + JavaThread* thread = JavaThread::current(); 1.256 + ResourceMark rm(thread); 1.257 + RegisterMap reg_map(thread); 1.258 + frame fr = thread->last_frame(); 1.259 + fr.verify(®_map); 1.260 +} 1.261 + 1.262 + 1.263 +#endif // ASSERT 1.264 + 1.265 + 1.266 +void InterfaceSupport_init() { 1.267 +#ifdef ASSERT 1.268 + if (ScavengeALot || FullGCALot) { 1.269 + srand(ScavengeALotInterval * FullGCALotInterval); 1.270 + } 1.271 +#endif 1.272 +}