src/share/vm/runtime/interfaceSupport.cpp

Thu, 15 Dec 2016 19:48:32 -0500

author
tschatzl
date
Thu, 15 Dec 2016 19:48:32 -0500
changeset 8661
27ae9bbef86a
parent 7875
fb260f267e87
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

8147910: Cache initial active_processor_count
Summary: Introduce and initialize active_processor_count variable in VM.
Reviewed-by: dholmes, jprovino

duke@435 1 /*
drchase@6680 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "gc_implementation/shared/markSweep.hpp"
stefank@2314 27 #include "gc_interface/collectedHeap.hpp"
stefank@2314 28 #include "gc_interface/collectedHeap.inline.hpp"
stefank@2314 29 #include "memory/genCollectedHeap.hpp"
stefank@2314 30 #include "memory/resourceArea.hpp"
stefank@2314 31 #include "runtime/init.hpp"
stefank@2314 32 #include "runtime/interfaceSupport.hpp"
goetz@6911 33 #include "runtime/orderAccess.inline.hpp"
stefank@2314 34 #include "runtime/threadLocalStorage.hpp"
stefank@2314 35 #include "runtime/vframe.hpp"
stefank@2314 36 #include "utilities/preserveException.hpp"
duke@435 37
drchase@6680 38 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
duke@435 39
duke@435 40 // Implementation of InterfaceSupport
duke@435 41
duke@435 42 #ifdef ASSERT
duke@435 43
duke@435 44 long InterfaceSupport::_number_of_calls = 0;
duke@435 45 long InterfaceSupport::_scavenge_alot_counter = 1;
duke@435 46 long InterfaceSupport::_fullgc_alot_counter = 1;
duke@435 47 long InterfaceSupport::_fullgc_alot_invocation = 0;
duke@435 48
duke@435 49 Histogram* RuntimeHistogram;
duke@435 50
duke@435 51 RuntimeHistogramElement::RuntimeHistogramElement(const char* elementName) {
duke@435 52 static volatile jint RuntimeHistogram_lock = 0;
duke@435 53 _name = elementName;
duke@435 54 uintx count = 0;
duke@435 55
duke@435 56 while (Atomic::cmpxchg(1, &RuntimeHistogram_lock, 0) != 0) {
duke@435 57 while (OrderAccess::load_acquire(&RuntimeHistogram_lock) != 0) {
duke@435 58 count +=1;
duke@435 59 if ( (WarnOnStalledSpinLock > 0)
duke@435 60 && (count % WarnOnStalledSpinLock == 0)) {
duke@435 61 warning("RuntimeHistogram_lock seems to be stalled");
duke@435 62 }
duke@435 63 }
duke@435 64 }
duke@435 65
duke@435 66 if (RuntimeHistogram == NULL) {
duke@435 67 RuntimeHistogram = new Histogram("VM Runtime Call Counts",200);
duke@435 68 }
duke@435 69
duke@435 70 RuntimeHistogram->add_element(this);
duke@435 71 Atomic::dec(&RuntimeHistogram_lock);
duke@435 72 }
duke@435 73
duke@435 74 void InterfaceSupport::trace(const char* result_type, const char* header) {
duke@435 75 tty->print_cr("%6d %s", _number_of_calls, header);
duke@435 76 }
duke@435 77
duke@435 78 void InterfaceSupport::gc_alot() {
duke@435 79 Thread *thread = Thread::current();
ysr@1241 80 if (!thread->is_Java_thread()) return; // Avoid concurrent calls
duke@435 81 // Check for new, not quite initialized thread. A thread in new mode cannot initiate a GC.
duke@435 82 JavaThread *current_thread = (JavaThread *)thread;
duke@435 83 if (current_thread->active_handles() == NULL) return;
duke@435 84
ysr@1241 85 // Short-circuit any possible re-entrant gc-a-lot attempt
ysr@1241 86 if (thread->skip_gcalot()) return;
ysr@1241 87
kbarrett@7360 88 if (Threads::is_vm_complete()) {
duke@435 89
duke@435 90 if (++_fullgc_alot_invocation < FullGCALotStart) {
duke@435 91 return;
duke@435 92 }
duke@435 93
duke@435 94 // Use this line if you want to block at a specific point,
duke@435 95 // e.g. one number_of_calls/scavenge/gc before you got into problems
duke@435 96 if (FullGCALot) _fullgc_alot_counter--;
duke@435 97
duke@435 98 // Check if we should force a full gc
duke@435 99 if (_fullgc_alot_counter == 0) {
duke@435 100 // Release dummy so objects are forced to move
duke@435 101 if (!Universe::release_fullgc_alot_dummy()) {
duke@435 102 warning("FullGCALot: Unable to release more dummies at bottom of heap");
duke@435 103 }
duke@435 104 HandleMark hm(thread);
duke@435 105 Universe::heap()->collect(GCCause::_full_gc_alot);
duke@435 106 unsigned int invocations = Universe::heap()->total_full_collections();
duke@435 107 // Compute new interval
duke@435 108 if (FullGCALotInterval > 1) {
duke@435 109 _fullgc_alot_counter = 1+(long)((double)FullGCALotInterval*os::random()/(max_jint+1.0));
duke@435 110 if (PrintGCDetails && Verbose) {
duke@435 111 tty->print_cr("Full gc no: %u\tInterval: %d", invocations,
duke@435 112 _fullgc_alot_counter);
duke@435 113 }
duke@435 114 } else {
duke@435 115 _fullgc_alot_counter = 1;
duke@435 116 }
duke@435 117 // Print progress message
duke@435 118 if (invocations % 100 == 0) {
duke@435 119 if (PrintGCDetails && Verbose) tty->print_cr("Full gc no: %u", invocations);
duke@435 120 }
duke@435 121 } else {
duke@435 122 if (ScavengeALot) _scavenge_alot_counter--;
duke@435 123 // Check if we should force a scavenge
duke@435 124 if (_scavenge_alot_counter == 0) {
duke@435 125 HandleMark hm(thread);
duke@435 126 Universe::heap()->collect(GCCause::_scavenge_alot);
duke@435 127 unsigned int invocations = Universe::heap()->total_collections() - Universe::heap()->total_full_collections();
duke@435 128 // Compute new interval
duke@435 129 if (ScavengeALotInterval > 1) {
duke@435 130 _scavenge_alot_counter = 1+(long)((double)ScavengeALotInterval*os::random()/(max_jint+1.0));
duke@435 131 if (PrintGCDetails && Verbose) {
duke@435 132 tty->print_cr("Scavenge no: %u\tInterval: %d", invocations,
duke@435 133 _scavenge_alot_counter);
duke@435 134 }
duke@435 135 } else {
duke@435 136 _scavenge_alot_counter = 1;
duke@435 137 }
duke@435 138 // Print progress message
duke@435 139 if (invocations % 1000 == 0) {
duke@435 140 if (PrintGCDetails && Verbose) tty->print_cr("Scavenge no: %u", invocations);
duke@435 141 }
duke@435 142 }
duke@435 143 }
duke@435 144 }
duke@435 145 }
duke@435 146
duke@435 147
duke@435 148 vframe* vframe_array[50];
duke@435 149 int walk_stack_counter = 0;
duke@435 150
duke@435 151 void InterfaceSupport::walk_stack_from(vframe* start_vf) {
duke@435 152 // walk
duke@435 153 int i = 0;
duke@435 154 for (vframe* f = start_vf; f; f = f->sender() ) {
duke@435 155 if (i < 50) vframe_array[i++] = f;
duke@435 156 }
duke@435 157 }
duke@435 158
duke@435 159
duke@435 160 void InterfaceSupport::walk_stack() {
duke@435 161 JavaThread* thread = JavaThread::current();
duke@435 162 walk_stack_counter++;
duke@435 163 if (!thread->has_last_Java_frame()) return;
duke@435 164 ResourceMark rm(thread);
duke@435 165 RegisterMap reg_map(thread);
duke@435 166 walk_stack_from(thread->last_java_vframe(&reg_map));
duke@435 167 }
duke@435 168
duke@435 169
duke@435 170 # ifdef ENABLE_ZAP_DEAD_LOCALS
duke@435 171
duke@435 172 static int zap_traversals = 0;
duke@435 173
duke@435 174 void InterfaceSupport::zap_dead_locals_old() {
duke@435 175 JavaThread* thread = JavaThread::current();
duke@435 176 if (zap_traversals == -1) // edit constant for debugging
duke@435 177 warning("I am here");
duke@435 178 int zap_frame_count = 0; // count frames to help debugging
duke@435 179 for (StackFrameStream sfs(thread); !sfs.is_done(); sfs.next()) {
duke@435 180 sfs.current()->zap_dead_locals(thread, sfs.register_map());
duke@435 181 ++zap_frame_count;
duke@435 182 }
duke@435 183 ++zap_traversals;
duke@435 184 }
duke@435 185
duke@435 186 # endif
duke@435 187
iignatyev@7875 188 // invocation counter for InterfaceSupport::deoptimizeAll/zombieAll functions
duke@435 189 int deoptimizeAllCounter = 0;
duke@435 190 int zombieAllCounter = 0;
duke@435 191
duke@435 192 void InterfaceSupport::zombieAll() {
iignatyev@7875 193 // This method is called by all threads when a thread make
iignatyev@7875 194 // transition to VM state (for example, runtime calls).
iignatyev@7875 195 // Divide number of calls by number of threads to avoid
iignatyev@7875 196 // dependence of ZombieAll events frequency on number of threads.
iignatyev@7875 197 int value = zombieAllCounter / Threads::number_of_threads();
iignatyev@7875 198 if (is_init_completed() && value > ZombieALotInterval) {
duke@435 199 zombieAllCounter = 0;
duke@435 200 VM_ZombieAll op;
duke@435 201 VMThread::execute(&op);
duke@435 202 }
iignatyev@7875 203 zombieAllCounter++;
duke@435 204 }
duke@435 205
coleenp@2497 206 void InterfaceSupport::unlinkSymbols() {
coleenp@2497 207 VM_UnlinkSymbols op;
coleenp@2497 208 VMThread::execute(&op);
coleenp@2497 209 }
coleenp@2497 210
duke@435 211 void InterfaceSupport::deoptimizeAll() {
iignatyev@7875 212 // This method is called by all threads when a thread make
iignatyev@7875 213 // transition to VM state (for example, runtime calls).
iignatyev@7875 214 // Divide number of calls by number of threads to avoid
iignatyev@7875 215 // dependence of DeoptimizeAll events frequency on number of threads.
iignatyev@7875 216 int value = deoptimizeAllCounter / Threads::number_of_threads();
iignatyev@7875 217 if (is_init_completed()) {
iignatyev@7875 218 if (DeoptimizeALot && value > DeoptimizeALotInterval) {
duke@435 219 deoptimizeAllCounter = 0;
duke@435 220 VM_DeoptimizeAll op;
duke@435 221 VMThread::execute(&op);
iignatyev@7875 222 } else if (DeoptimizeRandom && (value & 0x1F) == (os::random() & 0x1F)) {
duke@435 223 VM_DeoptimizeAll op;
duke@435 224 VMThread::execute(&op);
duke@435 225 }
duke@435 226 }
duke@435 227 deoptimizeAllCounter++;
duke@435 228 }
duke@435 229
duke@435 230
duke@435 231 void InterfaceSupport::stress_derived_pointers() {
duke@435 232 #ifdef COMPILER2
duke@435 233 JavaThread *thread = JavaThread::current();
duke@435 234 if (!is_init_completed()) return;
duke@435 235 ResourceMark rm(thread);
duke@435 236 bool found = false;
duke@435 237 for (StackFrameStream sfs(thread); !sfs.is_done() && !found; sfs.next()) {
duke@435 238 CodeBlob* cb = sfs.current()->cb();
duke@435 239 if (cb != NULL && cb->oop_maps() ) {
duke@435 240 // Find oopmap for current method
duke@435 241 OopMap* map = cb->oop_map_for_return_address(sfs.current()->pc());
duke@435 242 assert(map != NULL, "no oopmap found for pc");
duke@435 243 found = map->has_derived_pointer();
duke@435 244 }
duke@435 245 }
duke@435 246 if (found) {
duke@435 247 // $$$ Not sure what to do here.
duke@435 248 /*
duke@435 249 Scavenge::invoke(0);
duke@435 250 */
duke@435 251 }
duke@435 252 #endif
duke@435 253 }
duke@435 254
duke@435 255
duke@435 256 void InterfaceSupport::verify_stack() {
duke@435 257 JavaThread* thread = JavaThread::current();
duke@435 258 ResourceMark rm(thread);
duke@435 259 // disabled because it throws warnings that oop maps should only be accessed
duke@435 260 // in VM thread or during debugging
duke@435 261
duke@435 262 if (!thread->has_pending_exception()) {
duke@435 263 // verification does not work if there are pending exceptions
duke@435 264 StackFrameStream sfs(thread);
duke@435 265 CodeBlob* cb = sfs.current()->cb();
duke@435 266 // In case of exceptions we might not have a runtime_stub on
duke@435 267 // top of stack, hence, all callee-saved registers are not going
duke@435 268 // to be setup correctly, hence, we cannot do stack verify
duke@435 269 if (cb != NULL && !(cb->is_runtime_stub() || cb->is_uncommon_trap_stub())) return;
duke@435 270
duke@435 271 for (; !sfs.is_done(); sfs.next()) {
duke@435 272 sfs.current()->verify(sfs.register_map());
duke@435 273 }
duke@435 274 }
duke@435 275 }
duke@435 276
duke@435 277
duke@435 278 void InterfaceSupport::verify_last_frame() {
duke@435 279 JavaThread* thread = JavaThread::current();
duke@435 280 ResourceMark rm(thread);
duke@435 281 RegisterMap reg_map(thread);
duke@435 282 frame fr = thread->last_frame();
duke@435 283 fr.verify(&reg_map);
duke@435 284 }
duke@435 285
duke@435 286
duke@435 287 #endif // ASSERT
duke@435 288
duke@435 289
duke@435 290 void InterfaceSupport_init() {
duke@435 291 #ifdef ASSERT
duke@435 292 if (ScavengeALot || FullGCALot) {
duke@435 293 srand(ScavengeALotInterval * FullGCALotInterval);
duke@435 294 }
duke@435 295 #endif
duke@435 296 }

mercurial