Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/runtime/interfaceSupport.cpp
32285 views
/*1* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "gc_implementation/shared/markSweep.hpp"26#include "gc_interface/collectedHeap.hpp"27#include "gc_interface/collectedHeap.inline.hpp"28#include "memory/genCollectedHeap.hpp"29#include "memory/resourceArea.hpp"30#include "runtime/init.hpp"31#include "runtime/interfaceSupport.hpp"32#include "runtime/orderAccess.inline.hpp"33#include "runtime/threadLocalStorage.hpp"34#include "runtime/vframe.hpp"35#include "utilities/preserveException.hpp"3637PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC3839// Implementation of InterfaceSupport4041#ifdef ASSERT4243long InterfaceSupport::_number_of_calls = 0;44long InterfaceSupport::_scavenge_alot_counter = 1;45long InterfaceSupport::_fullgc_alot_counter = 1;46long InterfaceSupport::_fullgc_alot_invocation = 0;4748Histogram* RuntimeHistogram;4950RuntimeHistogramElement::RuntimeHistogramElement(const char* elementName) {51static volatile jint RuntimeHistogram_lock = 0;52_name = elementName;53uintx count = 0;5455while (Atomic::cmpxchg(1, &RuntimeHistogram_lock, 0) != 0) {56while (OrderAccess::load_acquire(&RuntimeHistogram_lock) != 0) {57count +=1;58if ( (WarnOnStalledSpinLock > 0)59&& (count % WarnOnStalledSpinLock == 0)) {60warning("RuntimeHistogram_lock seems to be stalled");61}62}63}6465if (RuntimeHistogram == NULL) {66RuntimeHistogram = new Histogram("VM Runtime Call Counts",200);67}6869RuntimeHistogram->add_element(this);70Atomic::dec(&RuntimeHistogram_lock);71}7273void InterfaceSupport::trace(const char* result_type, const char* header) {74tty->print_cr("%6d %s", _number_of_calls, header);75}7677void InterfaceSupport::gc_alot() {78Thread *thread = Thread::current();79if (!thread->is_Java_thread()) return; // Avoid concurrent calls80// Check for new, not quite initialized thread. A thread in new mode cannot initiate a GC.81JavaThread *current_thread = (JavaThread *)thread;82if (current_thread->active_handles() == NULL) return;8384// Short-circuit any possible re-entrant gc-a-lot attempt85if (thread->skip_gcalot()) return;8687if (Threads::is_vm_complete()) {8889if (++_fullgc_alot_invocation < FullGCALotStart) {90return;91}9293// Use this line if you want to block at a specific point,94// e.g. one number_of_calls/scavenge/gc before you got into problems95if (FullGCALot) _fullgc_alot_counter--;9697// Check if we should force a full gc98if (_fullgc_alot_counter == 0) {99// Release dummy so objects are forced to move100if (!Universe::release_fullgc_alot_dummy()) {101warning("FullGCALot: Unable to release more dummies at bottom of heap");102}103HandleMark hm(thread);104Universe::heap()->collect(GCCause::_full_gc_alot);105unsigned int invocations = Universe::heap()->total_full_collections();106// Compute new interval107if (FullGCALotInterval > 1) {108_fullgc_alot_counter = 1+(long)((double)FullGCALotInterval*os::random()/(max_jint+1.0));109if (PrintGCDetails && Verbose) {110tty->print_cr("Full gc no: %u\tInterval: %d", invocations,111_fullgc_alot_counter);112}113} else {114_fullgc_alot_counter = 1;115}116// Print progress message117if (invocations % 100 == 0) {118if (PrintGCDetails && Verbose) tty->print_cr("Full gc no: %u", invocations);119}120} else {121if (ScavengeALot) _scavenge_alot_counter--;122// Check if we should force a scavenge123if (_scavenge_alot_counter == 0) {124HandleMark hm(thread);125Universe::heap()->collect(GCCause::_scavenge_alot);126unsigned int invocations = Universe::heap()->total_collections() - Universe::heap()->total_full_collections();127// Compute new interval128if (ScavengeALotInterval > 1) {129_scavenge_alot_counter = 1+(long)((double)ScavengeALotInterval*os::random()/(max_jint+1.0));130if (PrintGCDetails && Verbose) {131tty->print_cr("Scavenge no: %u\tInterval: %d", invocations,132_scavenge_alot_counter);133}134} else {135_scavenge_alot_counter = 1;136}137// Print progress message138if (invocations % 1000 == 0) {139if (PrintGCDetails && Verbose) tty->print_cr("Scavenge no: %u", invocations);140}141}142}143}144}145146147vframe* vframe_array[50];148int walk_stack_counter = 0;149150void InterfaceSupport::walk_stack_from(vframe* start_vf) {151// walk152int i = 0;153for (vframe* f = start_vf; f; f = f->sender() ) {154if (i < 50) vframe_array[i++] = f;155}156}157158159void InterfaceSupport::walk_stack() {160JavaThread* thread = JavaThread::current();161walk_stack_counter++;162if (!thread->has_last_Java_frame()) return;163ResourceMark rm(thread);164RegisterMap reg_map(thread);165walk_stack_from(thread->last_java_vframe(®_map));166}167168169# ifdef ENABLE_ZAP_DEAD_LOCALS170171static int zap_traversals = 0;172173void InterfaceSupport::zap_dead_locals_old() {174JavaThread* thread = JavaThread::current();175if (zap_traversals == -1) // edit constant for debugging176warning("I am here");177int zap_frame_count = 0; // count frames to help debugging178for (StackFrameStream sfs(thread); !sfs.is_done(); sfs.next()) {179sfs.current()->zap_dead_locals(thread, sfs.register_map());180++zap_frame_count;181}182++zap_traversals;183}184185# endif186187// invocation counter for InterfaceSupport::deoptimizeAll/zombieAll functions188int deoptimizeAllCounter = 0;189int zombieAllCounter = 0;190191void InterfaceSupport::zombieAll() {192// This method is called by all threads when a thread make193// transition to VM state (for example, runtime calls).194// Divide number of calls by number of threads to avoid195// dependence of ZombieAll events frequency on number of threads.196int value = zombieAllCounter / Threads::number_of_threads();197if (is_init_completed() && value > ZombieALotInterval) {198zombieAllCounter = 0;199VM_ZombieAll op;200VMThread::execute(&op);201}202zombieAllCounter++;203}204205void InterfaceSupport::unlinkSymbols() {206VM_UnlinkSymbols op;207VMThread::execute(&op);208}209210void InterfaceSupport::deoptimizeAll() {211// This method is called by all threads when a thread make212// transition to VM state (for example, runtime calls).213// Divide number of calls by number of threads to avoid214// dependence of DeoptimizeAll events frequency on number of threads.215int value = deoptimizeAllCounter / Threads::number_of_threads();216if (is_init_completed()) {217if (DeoptimizeALot && value > DeoptimizeALotInterval) {218deoptimizeAllCounter = 0;219VM_DeoptimizeAll op;220VMThread::execute(&op);221} else if (DeoptimizeRandom && (value & 0x1F) == (os::random() & 0x1F)) {222VM_DeoptimizeAll op;223VMThread::execute(&op);224}225}226deoptimizeAllCounter++;227}228229230void InterfaceSupport::stress_derived_pointers() {231#ifdef COMPILER2232JavaThread *thread = JavaThread::current();233if (!is_init_completed()) return;234ResourceMark rm(thread);235bool found = false;236for (StackFrameStream sfs(thread); !sfs.is_done() && !found; sfs.next()) {237CodeBlob* cb = sfs.current()->cb();238if (cb != NULL && cb->oop_maps() ) {239// Find oopmap for current method240OopMap* map = cb->oop_map_for_return_address(sfs.current()->pc());241assert(map != NULL, "no oopmap found for pc");242found = map->has_derived_pointer();243}244}245if (found) {246// $$$ Not sure what to do here.247/*248Scavenge::invoke(0);249*/250}251#endif252}253254255void InterfaceSupport::verify_stack() {256JavaThread* thread = JavaThread::current();257ResourceMark rm(thread);258// disabled because it throws warnings that oop maps should only be accessed259// in VM thread or during debugging260261if (!thread->has_pending_exception()) {262// verification does not work if there are pending exceptions263StackFrameStream sfs(thread);264CodeBlob* cb = sfs.current()->cb();265// In case of exceptions we might not have a runtime_stub on266// top of stack, hence, all callee-saved registers are not going267// to be setup correctly, hence, we cannot do stack verify268if (cb != NULL && !(cb->is_runtime_stub() || cb->is_uncommon_trap_stub())) return;269270for (; !sfs.is_done(); sfs.next()) {271sfs.current()->verify(sfs.register_map());272}273}274}275276277void InterfaceSupport::verify_last_frame() {278JavaThread* thread = JavaThread::current();279ResourceMark rm(thread);280RegisterMap reg_map(thread);281frame fr = thread->last_frame();282fr.verify(®_map);283}284285286#endif // ASSERT287288289void InterfaceSupport_init() {290#ifdef ASSERT291if (ScavengeALot || FullGCALot) {292srand(ScavengeALotInterval * FullGCALotInterval);293}294#endif295}296297298