interfaceSupport.cpp revision 1472
0N/A/*
337N/A * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A *
0N/A */
0N/A
0N/A#include "incls/_precompiled.incl"
0N/A#include "incls/_interfaceSupport.cpp.incl"
0N/A
0N/A
0N/A// Implementation of InterfaceSupport
0N/A
0N/A#ifdef ASSERT
0N/A
0N/Along InterfaceSupport::_number_of_calls = 0;
0N/Along InterfaceSupport::_scavenge_alot_counter = 1;
0N/Along InterfaceSupport::_fullgc_alot_counter = 1;
0N/Along InterfaceSupport::_fullgc_alot_invocation = 0;
0N/A
0N/AHistogram* RuntimeHistogram;
0N/A
0N/ARuntimeHistogramElement::RuntimeHistogramElement(const char* elementName) {
0N/A static volatile jint RuntimeHistogram_lock = 0;
0N/A _name = elementName;
0N/A uintx count = 0;
0N/A
0N/A while (Atomic::cmpxchg(1, &RuntimeHistogram_lock, 0) != 0) {
0N/A while (OrderAccess::load_acquire(&RuntimeHistogram_lock) != 0) {
304N/A count +=1;
304N/A if ( (WarnOnStalledSpinLock > 0)
304N/A && (count % WarnOnStalledSpinLock == 0)) {
304N/A warning("RuntimeHistogram_lock seems to be stalled");
304N/A }
304N/A }
304N/A }
304N/A
0N/A if (RuntimeHistogram == NULL) {
0N/A RuntimeHistogram = new Histogram("VM Runtime Call Counts",200);
0N/A }
0N/A
0N/A RuntimeHistogram->add_element(this);
0N/A Atomic::dec(&RuntimeHistogram_lock);
0N/A}
0N/A
0N/Avoid InterfaceSupport::trace(const char* result_type, const char* header) {
0N/A tty->print_cr("%6d %s", _number_of_calls, header);
0N/A}
0N/A
0N/Avoid InterfaceSupport::gc_alot() {
0N/A Thread *thread = Thread::current();
0N/A if (!thread->is_Java_thread()) return; // Avoid concurrent calls
0N/A // Check for new, not quite initialized thread. A thread in new mode cannot initiate a GC.
0N/A JavaThread *current_thread = (JavaThread *)thread;
0N/A if (current_thread->active_handles() == NULL) return;
0N/A
0N/A // Short-circuit any possible re-entrant gc-a-lot attempt
0N/A if (thread->skip_gcalot()) return;
0N/A
0N/A if (is_init_completed()) {
0N/A
0N/A if (++_fullgc_alot_invocation < FullGCALotStart) {
0N/A return;
0N/A }
0N/A
0N/A // Use this line if you want to block at a specific point,
0N/A // e.g. one number_of_calls/scavenge/gc before you got into problems
0N/A if (FullGCALot) _fullgc_alot_counter--;
0N/A
0N/A // Check if we should force a full gc
0N/A if (_fullgc_alot_counter == 0) {
0N/A // Release dummy so objects are forced to move
0N/A if (!Universe::release_fullgc_alot_dummy()) {
0N/A warning("FullGCALot: Unable to release more dummies at bottom of heap");
0N/A }
0N/A HandleMark hm(thread);
0N/A Universe::heap()->collect(GCCause::_full_gc_alot);
0N/A unsigned int invocations = Universe::heap()->total_full_collections();
0N/A // Compute new interval
0N/A if (FullGCALotInterval > 1) {
0N/A _fullgc_alot_counter = 1+(long)((double)FullGCALotInterval*os::random()/(max_jint+1.0));
0N/A if (PrintGCDetails && Verbose) {
0N/A tty->print_cr("Full gc no: %u\tInterval: %d", invocations,
0N/A _fullgc_alot_counter);
0N/A }
0N/A } else {
0N/A _fullgc_alot_counter = 1;
0N/A }
0N/A // Print progress message
0N/A if (invocations % 100 == 0) {
304N/A if (PrintGCDetails && Verbose) tty->print_cr("Full gc no: %u", invocations);
0N/A }
0N/A } else {
304N/A if (ScavengeALot) _scavenge_alot_counter--;
304N/A // Check if we should force a scavenge
304N/A if (_scavenge_alot_counter == 0) {
0N/A HandleMark hm(thread);
0N/A Universe::heap()->collect(GCCause::_scavenge_alot);
0N/A unsigned int invocations = Universe::heap()->total_collections() - Universe::heap()->total_full_collections();
0N/A // Compute new interval
304N/A if (ScavengeALotInterval > 1) {
0N/A _scavenge_alot_counter = 1+(long)((double)ScavengeALotInterval*os::random()/(max_jint+1.0));
0N/A if (PrintGCDetails && Verbose) {
0N/A tty->print_cr("Scavenge no: %u\tInterval: %d", invocations,
0N/A _scavenge_alot_counter);
304N/A }
0N/A } else {
0N/A _scavenge_alot_counter = 1;
0N/A }
0N/A // Print progress message
0N/A if (invocations % 1000 == 0) {
0N/A if (PrintGCDetails && Verbose) tty->print_cr("Scavenge no: %u", invocations);
0N/A }
0N/A }
0N/A }
304N/A }
304N/A}
0N/A
0N/A
0N/Avframe* vframe_array[50];
0N/Aint walk_stack_counter = 0;
304N/A
0N/Avoid InterfaceSupport::walk_stack_from(vframe* start_vf) {
0N/A // walk
0N/A int i = 0;
0N/A for (vframe* f = start_vf; f; f = f->sender() ) {
0N/A if (i < 50) vframe_array[i++] = f;
0N/A }
0N/A}
0N/A
0N/A
0N/Avoid InterfaceSupport::walk_stack() {
0N/A JavaThread* thread = JavaThread::current();
0N/A walk_stack_counter++;
0N/A if (!thread->has_last_Java_frame()) return;
0N/A ResourceMark rm(thread);
0N/A RegisterMap reg_map(thread);
0N/A walk_stack_from(thread->last_java_vframe(&reg_map));
0N/A}
0N/A
0N/A
304N/A# ifdef ENABLE_ZAP_DEAD_LOCALS
0N/A
0N/Astatic int zap_traversals = 0;
0N/A
0N/Avoid InterfaceSupport::zap_dead_locals_old() {
0N/A JavaThread* thread = JavaThread::current();
0N/A if (zap_traversals == -1) // edit constant for debugging
0N/A warning("I am here");
304N/A int zap_frame_count = 0; // count frames to help debugging
0N/A for (StackFrameStream sfs(thread); !sfs.is_done(); sfs.next()) {
0N/A sfs.current()->zap_dead_locals(thread, sfs.register_map());
0N/A ++zap_frame_count;
0N/A }
0N/A ++zap_traversals;
304N/A}
0N/A
0N/A# endif
0N/A
0N/A
0N/Aint deoptimizeAllCounter = 0;
304N/Aint zombieAllCounter = 0;
0N/A
0N/A
0N/Avoid InterfaceSupport::zombieAll() {
0N/A if (is_init_completed() && zombieAllCounter > ZombieALotInterval) {
0N/A zombieAllCounter = 0;
304N/A VM_ZombieAll op;
0N/A VMThread::execute(&op);
0N/A } else {
304N/A zombieAllCounter++;
304N/A }
0N/A}
0N/A
304N/Avoid InterfaceSupport::deoptimizeAll() {
0N/A if (is_init_completed() ) {
0N/A if (DeoptimizeALot && deoptimizeAllCounter > DeoptimizeALotInterval) {
304N/A deoptimizeAllCounter = 0;
304N/A VM_DeoptimizeAll op;
0N/A VMThread::execute(&op);
304N/A } else if (DeoptimizeRandom && (deoptimizeAllCounter & 0x1f) == (os::random() & 0x1f)) {
0N/A VM_DeoptimizeAll op;
0N/A VMThread::execute(&op);
0N/A }
0N/A }
0N/A deoptimizeAllCounter++;
304N/A}
0N/A
304N/A
0N/Avoid InterfaceSupport::stress_derived_pointers() {
0N/A#ifdef COMPILER2
0N/A JavaThread *thread = JavaThread::current();
0N/A if (!is_init_completed()) return;
0N/A ResourceMark rm(thread);
0N/A bool found = false;
304N/A for (StackFrameStream sfs(thread); !sfs.is_done() && !found; sfs.next()) {
0N/A CodeBlob* cb = sfs.current()->cb();
0N/A if (cb != NULL && cb->oop_maps() ) {
0N/A // Find oopmap for current method
0N/A OopMap* map = cb->oop_map_for_return_address(sfs.current()->pc());
0N/A assert(map != NULL, "no oopmap found for pc");
0N/A found = map->has_derived_pointer();
0N/A }
0N/A }
0N/A if (found) {
0N/A // $$$ Not sure what to do here.
0N/A /*
304N/A Scavenge::invoke(0);
0N/A */
0N/A }
0N/A#endif
0N/A}
0N/A
0N/A
0N/Avoid InterfaceSupport::verify_stack() {
0N/A JavaThread* thread = JavaThread::current();
0N/A ResourceMark rm(thread);
304N/A // disabled because it throws warnings that oop maps should only be accessed
304N/A // in VM thread or during debugging
0N/A
0N/A if (!thread->has_pending_exception()) {
0N/A // verification does not work if there are pending exceptions
0N/A StackFrameStream sfs(thread);
0N/A CodeBlob* cb = sfs.current()->cb();
0N/A // In case of exceptions we might not have a runtime_stub on
0N/A // top of stack, hence, all callee-saved registers are not going
0N/A // to be setup correctly, hence, we cannot do stack verify
0N/A if (cb != NULL && !(cb->is_runtime_stub() || cb->is_uncommon_trap_stub())) return;
304N/A
304N/A for (; !sfs.is_done(); sfs.next()) {
0N/A sfs.current()->verify(sfs.register_map());
0N/A }
0N/A }
0N/A}
0N/A
0N/A
0N/Avoid InterfaceSupport::verify_last_frame() {
0N/A JavaThread* thread = JavaThread::current();
304N/A ResourceMark rm(thread);
304N/A RegisterMap reg_map(thread);
0N/A frame fr = thread->last_frame();
304N/A fr.verify(&reg_map);
0N/A}
0N/A
0N/A
0N/A#endif // ASSERT
0N/A
0N/A
0N/Avoid InterfaceSupport_init() {
0N/A#ifdef ASSERT
304N/A if (ScavengeALot || FullGCALot) {
304N/A srand(ScavengeALotInterval * FullGCALotInterval);
304N/A }
304N/A#endif
304N/A}
304N/A