src/hotspot/share/runtime/interfaceSupport.cpp
author coleenp
Mon, 29 Apr 2019 16:01:52 -0400
changeset 54645 05aaccf7d558
parent 50946 be2d74d91351
child 54786 ebf733a324d4
permissions -rw-r--r--
8222988: Use MonitorLocker rather than MutexLocker when wait/notify used Summary: fixed use cases in code except CMS. Reviewed-by: rehn, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49449
diff changeset
     2
 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30590
diff changeset
    26
#include "gc/shared/collectedHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30590
diff changeset
    27
#include "gc/shared/collectedHeap.inline.hpp"
50882
80abf702eed8 8205683: Refactor heap allocation to separate concerns
eosterlund
parents: 50429
diff changeset
    28
#include "logging/log.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "memory/resourceArea.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 35061
diff changeset
    30
#include "runtime/atomic.hpp"
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49449
diff changeset
    31
#include "runtime/frame.inline.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    32
#include "runtime/handles.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    33
#include "runtime/init.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    34
#include "runtime/interfaceSupport.inline.hpp"
50429
83aec1d357d4 8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents: 49734
diff changeset
    35
#include "runtime/orderAccess.hpp"
25468
5331df506290 8048241: Introduce umbrella header os.inline.hpp and clean up includes
goetz
parents: 25351
diff changeset
    36
#include "runtime/os.inline.hpp"
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    37
#include "runtime/thread.inline.hpp"
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
    38
#include "runtime/safepointVerifiers.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    39
#include "runtime/vframe.hpp"
49480
d7df2dd501ce 8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents: 49449
diff changeset
    40
#include "runtime/vmThread.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    41
#include "utilities/preserveException.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// Implementation of InterfaceSupport
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
#ifdef ASSERT
49449
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    46
VMEntryWrapper::VMEntryWrapper() {
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    47
  if (VerifyLastFrame) {
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    48
    InterfaceSupport::verify_last_frame();
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    49
  }
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    50
}
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    51
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    52
VMEntryWrapper::~VMEntryWrapper() {
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    53
  InterfaceSupport::check_gc_alot();
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    54
  if (WalkStackALot) {
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    55
    InterfaceSupport::walk_stack();
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    56
  }
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    57
#ifdef COMPILER2
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    58
  // This option is not used by Compiler 1
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    59
  if (StressDerivedPointers) {
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    60
    InterfaceSupport::stress_derived_pointers();
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    61
  }
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    62
#endif
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    63
  if (DeoptimizeALot || DeoptimizeRandom) {
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    64
    InterfaceSupport::deoptimizeAll();
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    65
  }
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    66
  if (ZombieALot) {
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    67
    InterfaceSupport::zombieAll();
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    68
  }
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    69
  // do verification AFTER potential deoptimization
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    70
  if (VerifyStack) {
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    71
    InterfaceSupport::verify_stack();
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    72
  }
ef5d5d343e2a 8199263: Split interfaceSupport.hpp to not require including .inline.hpp files
coleenp
parents: 47765
diff changeset
    73
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
long InterfaceSupport::_number_of_calls       = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
long InterfaceSupport::_scavenge_alot_counter = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
long InterfaceSupport::_fullgc_alot_counter   = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
long InterfaceSupport::_fullgc_alot_invocation = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
Histogram* RuntimeHistogram;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
RuntimeHistogramElement::RuntimeHistogramElement(const char* elementName) {
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    83
  static volatile int RuntimeHistogram_lock = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  _name = elementName;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  uintx count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  while (Atomic::cmpxchg(1, &RuntimeHistogram_lock, 0) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    while (OrderAccess::load_acquire(&RuntimeHistogram_lock) != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      count +=1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
      if ( (WarnOnStalledSpinLock > 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
        && (count % WarnOnStalledSpinLock == 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
        warning("RuntimeHistogram_lock seems to be stalled");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  if (RuntimeHistogram == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    RuntimeHistogram = new Histogram("VM Runtime Call Counts",200);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  RuntimeHistogram->add_element(this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  Atomic::dec(&RuntimeHistogram_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
void InterfaceSupport::gc_alot() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  Thread *thread = Thread::current();
2995
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 1
diff changeset
   107
  if (!thread->is_Java_thread()) return; // Avoid concurrent calls
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // Check for new, not quite initialized thread. A thread in new mode cannot initiate a GC.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  JavaThread *current_thread = (JavaThread *)thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  if (current_thread->active_handles() == NULL) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
2995
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 1
diff changeset
   112
  // Short-circuit any possible re-entrant gc-a-lot attempt
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 1
diff changeset
   113
  if (thread->skip_gcalot()) return;
d8283445992a 6820167: GCALotAtAllSafepoints + FullGCALot(ScavengeALot) options crash JVM
ysr
parents: 1
diff changeset
   114
27678
d1872bc7dd8d 8062036: ConcurrentMarkThread::slt may be invoked before ConcurrentMarkThread::makeSurrogateLockerThread causing intermittent crashes
kbarrett
parents: 25468
diff changeset
   115
  if (Threads::is_vm_complete()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    if (++_fullgc_alot_invocation < FullGCALotStart) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    // Use this line if you want to block at a specific point,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    // e.g. one number_of_calls/scavenge/gc before you got into problems
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    if (FullGCALot) _fullgc_alot_counter--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    // Check if we should force a full gc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    if (_fullgc_alot_counter == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
      // Release dummy so objects are forced to move
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      if (!Universe::release_fullgc_alot_dummy()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
        warning("FullGCALot: Unable to release more dummies at bottom of heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      HandleMark hm(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      Universe::heap()->collect(GCCause::_full_gc_alot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
      unsigned int invocations = Universe::heap()->total_full_collections();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      // Compute new interval
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      if (FullGCALotInterval > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
        _fullgc_alot_counter = 1+(long)((double)FullGCALotInterval*os::random()/(max_jint+1.0));
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34633
diff changeset
   137
        log_trace(gc)("Full gc no: %u\tInterval: %ld", invocations, _fullgc_alot_counter);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
        _fullgc_alot_counter = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
      // Print progress message
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      if (invocations % 100 == 0) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34633
diff changeset
   143
        log_trace(gc)("Full gc no: %u", invocations);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      if (ScavengeALot) _scavenge_alot_counter--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      // Check if we should force a scavenge
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      if (_scavenge_alot_counter == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
        HandleMark hm(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
        Universe::heap()->collect(GCCause::_scavenge_alot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
        unsigned int invocations = Universe::heap()->total_collections() - Universe::heap()->total_full_collections();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
        // Compute new interval
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
        if (ScavengeALotInterval > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
          _scavenge_alot_counter = 1+(long)((double)ScavengeALotInterval*os::random()/(max_jint+1.0));
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34633
diff changeset
   155
          log_trace(gc)("Scavenge no: %u\tInterval: %ld", invocations, _scavenge_alot_counter);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
          _scavenge_alot_counter = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
        // Print progress message
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
        if (invocations % 1000 == 0) {
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 34633
diff changeset
   161
          log_trace(gc)("Scavenge no: %u", invocations);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
vframe* vframe_array[50];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
int walk_stack_counter = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
void InterfaceSupport::walk_stack_from(vframe* start_vf) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // walk
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  int i = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  for (vframe* f = start_vf; f; f = f->sender() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    if (i < 50) vframe_array[i++] = f;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
void InterfaceSupport::walk_stack() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  JavaThread* thread = JavaThread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  walk_stack_counter++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  if (!thread->has_last_Java_frame()) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  ResourceMark rm(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  RegisterMap reg_map(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  walk_stack_from(thread->last_java_vframe(&reg_map));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
27451
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   190
// invocation counter for InterfaceSupport::deoptimizeAll/zombieAll functions
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
int deoptimizeAllCounter = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
int zombieAllCounter = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
void InterfaceSupport::zombieAll() {
27451
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   195
  // This method is called by all threads when a thread make
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   196
  // transition to VM state (for example, runtime calls).
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   197
  // Divide number of calls by number of threads to avoid
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   198
  // dependence of ZombieAll events frequency on number of threads.
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   199
  int value = zombieAllCounter / Threads::number_of_threads();
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   200
  if (is_init_completed() && value > ZombieALotInterval) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    zombieAllCounter = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    VM_ZombieAll op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
27451
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   205
  zombieAllCounter++;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
void InterfaceSupport::deoptimizeAll() {
27451
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   209
  // This method is called by all threads when a thread make
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   210
  // transition to VM state (for example, runtime calls).
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   211
  // Divide number of calls by number of threads to avoid
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   212
  // dependence of DeoptimizeAll events frequency on number of threads.
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   213
  int value = deoptimizeAllCounter / Threads::number_of_threads();
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   214
  if (is_init_completed()) {
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   215
    if (DeoptimizeALot && value > DeoptimizeALotInterval) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      deoptimizeAllCounter = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
      VM_DeoptimizeAll op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
      VMThread::execute(&op);
27451
7e2e2b955d15 8036913: make DeoptimizeALot dependent on number of threads
iignatyev
parents: 25468
diff changeset
   219
    } else if (DeoptimizeRandom && (value & 0x1F) == (os::random() & 0x1F)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
      VM_DeoptimizeAll op;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      VMThread::execute(&op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  deoptimizeAllCounter++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
void InterfaceSupport::stress_derived_pointers() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
#ifdef COMPILER2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  JavaThread *thread = JavaThread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  if (!is_init_completed()) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  ResourceMark rm(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  bool found = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  for (StackFrameStream sfs(thread); !sfs.is_done() && !found; sfs.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    CodeBlob* cb = sfs.current()->cb();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
    if (cb != NULL && cb->oop_maps() ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
      // Find oopmap for current method
30590
14f7f48c1377 8064458: OopMap class could be more compact
rbackman
parents: 29204
diff changeset
   238
      const ImmutableOopMap* map = cb->oop_map_for_return_address(sfs.current()->pc());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
      assert(map != NULL, "no oopmap found for pc");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
      found = map->has_derived_pointer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  if (found) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    // $$$ Not sure what to do here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    /*
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    Scavenge::invoke(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    */
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
void InterfaceSupport::verify_stack() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  JavaThread* thread = JavaThread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  ResourceMark rm(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  // disabled because it throws warnings that oop maps should only be accessed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  // in VM thread or during debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  if (!thread->has_pending_exception()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    // verification does not work if there are pending exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    StackFrameStream sfs(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    CodeBlob* cb = sfs.current()->cb();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
      // In case of exceptions we might not have a runtime_stub on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
      // top of stack, hence, all callee-saved registers are not going
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
      // to be setup correctly, hence, we cannot do stack verify
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    if (cb != NULL && !(cb->is_runtime_stub() || cb->is_uncommon_trap_stub())) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    for (; !sfs.is_done(); sfs.next()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      sfs.current()->verify(sfs.register_map());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
void InterfaceSupport::verify_last_frame() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  JavaThread* thread = JavaThread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  ResourceMark rm(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  RegisterMap reg_map(thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  frame fr = thread->last_frame();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  fr.verify(&reg_map);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
void InterfaceSupport_init() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  if (ScavengeALot || FullGCALot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    srand(ScavengeALotInterval * FullGCALotInterval);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
}
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   294
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   295
#ifdef ASSERT
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   296
// JRT_LEAF rules:
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   297
// A JRT_LEAF method may not interfere with safepointing by
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   298
//   1) acquiring or blocking on a Mutex or JavaLock - checked
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   299
//   2) allocating heap memory - checked
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   300
//   3) executing a VM operation - checked
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   301
//   4) executing a system call (including malloc) that could block or grab a lock
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   302
//   5) invoking GC
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   303
//   6) reaching a safepoint
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   304
//   7) running too long
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   305
// Nor may any method it calls.
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   306
JRTLeafVerifier::JRTLeafVerifier()
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   307
  : NoSafepointVerifier(true, JRTLeafVerifier::should_verify_GC())
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   308
{
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   309
}
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   310
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   311
JRTLeafVerifier::~JRTLeafVerifier()
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   312
{
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   313
}
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   314
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   315
bool JRTLeafVerifier::should_verify_GC() {
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   316
  switch (JavaThread::current()->thread_state()) {
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   317
  case _thread_in_Java:
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   318
    // is in a leaf routine, there must be no safepoint.
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   319
    return true;
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   320
  case _thread_in_native:
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   321
    // A native thread is not subject to safepoints.
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   322
    // Even while it is in a leaf routine, GC is ok
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   323
    return false;
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   324
  default:
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   325
    // Leaf routines cannot be called from other contexts.
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   326
    ShouldNotReachHere();
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   327
    return false;
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   328
  }
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   329
}
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49480
diff changeset
   330
#endif // ASSERT