void SafepointSynchronize::do_cleanup_tasks() {
{
const char* name = "deflating idle monitors";
EventSafepointCleanupTask event;
TraceTime t1(name, TraceSafepointCleanupTime);
ObjectSynchronizer::deflate_idle_monitors();
if (event.should_commit()) {
post_safepoint_cleanup_task_event(&event, name);
}
}
{
const char* name = "updating inline caches";
EventSafepointCleanupTask event;
TraceTime t2(name, TraceSafepointCleanupTime);
InlineCacheBuffer::update_inline_caches();
if (event.should_commit()) {
post_safepoint_cleanup_task_event(&event, name);
}
}
{
const char* name = "compilation policy safepoint handler";
EventSafepointCleanupTask event;
TraceTime t3(name, TraceSafepointCleanupTime);
CompilationPolicy::policy()->do_safepoint_work();
if (event.should_commit()) {
post_safepoint_cleanup_task_event(&event, name);
}
}
{
const char* name = "mark nmethods";
EventSafepointCleanupTask event;
TraceTime t4(name, TraceSafepointCleanupTime);
NMethodSweeper::mark_active_nmethods();
if (event.should_commit()) {
post_safepoint_cleanup_task_event(&event, name);
}
}
if (SymbolTable::needs_rehashing()) {
const char* name = "rehashing symbol table";
EventSafepointCleanupTask event;
TraceTime t5(name, TraceSafepointCleanupTime);
SymbolTable::rehash_table();
if (event.should_commit()) {
post_safepoint_cleanup_task_event(&event, name);
}
}
if (StringTable::needs_rehashing()) {
const char* name = "rehashing string table";
EventSafepointCleanupTask event;
TraceTime t6(name, TraceSafepointCleanupTime);
StringTable::rehash_table();
if (event.should_commit()) {
post_safepoint_cleanup_task_event(&event, name);
}
}
if (UseGCLogFileRotation) {
TraceTime t8("rotating gc logs", TraceSafepointCleanupTime);
gclog_or_tty->rotate_log(false);
}
{
TraceTime t7("purging class loader data graph", TraceSafepointCleanupTime);
ClassLoaderDataGraph::purge_if_needed();
}
}
bool SafepointSynchronize::safepoint_safe(JavaThread *thread, JavaThreadState state) {
switch(state) {
case _thread_in_native:
return !thread->has_last_Java_frame() || thread->frame_anchor()->walkable();
case _thread_blocked:
assert(!thread->has_last_Java_frame() || thread->frame_anchor()->walkable(), "blocked and not walkable");
return true;
default:
return false;
}
}
void SafepointSynchronize::check_for_lazy_critical_native(JavaThread *thread, JavaThreadState state) {
if (state == _thread_in_native &&
thread->has_last_Java_frame() &&
thread->frame_anchor()->walkable()) {
frame wrapper_frame = thread->last_frame();
CodeBlob* stub_cb = wrapper_frame.cb();
if (stub_cb != NULL &&
stub_cb->is_nmethod() &&
stub_cb->as_nmethod_or_null()->is_lazy_critical_native()) {
if (!thread->do_critical_native_unlock()) {
#ifdef ASSERT
if (!thread->in_critical()) {
GC_locker::increment_debug_jni_lock_count();
}
#endif
thread->enter_critical();
thread->set_critical_native_unlock();
}
}
}
}
void SafepointSynchronize::block(JavaThread *thread) {
assert(thread != NULL, "thread must be set");
assert(thread->is_Java_thread(), "not a Java thread");
ttyLocker::break_tty_lock_for_safepoint(os::current_thread_id());
if (thread->is_terminated()) {
thread->block_if_vm_exited();
return;
}
JavaThreadState state = thread->thread_state();
thread->frame_anchor()->make_walkable(thread);
switch(state) {
case _thread_in_vm_trans:
case _thread_in_Java: // From compiled code
thread->set_thread_state(_thread_in_vm);
if (is_synchronizing()) {
Atomic::inc (&TryingToBlock) ;
}
Safepoint_lock->lock_without_safepoint_check();
if (is_synchronizing()) {
assert(_waiting_to_block > 0, "sanity check");
_waiting_to_block--;
thread->safepoint_state()->set_has_called_back(true);
DEBUG_ONLY(thread->set_visited_for_critical_count(true));
if (thread->in_critical()) {
increment_jni_active_count();
}
if (_waiting_to_block == 0) {
Safepoint_lock->notify_all();
}
}
thread->set_thread_state(_thread_blocked);
Safepoint_lock->unlock();
Threads_lock->lock_without_safepoint_check();
thread->set_thread_state(state);
Threads_lock->unlock();
break;
case _thread_in_native_trans:
case _thread_blocked_trans:
case _thread_new_trans:
if (thread->safepoint_state()->type() == ThreadSafepointState::_call_back) {
thread->print_thread_state();
fatal("Deadlock in safepoint code. "
"Should have called back to the VM before blocking.");
}
thread->set_thread_state(_thread_blocked);
Threads_lock->lock_without_safepoint_check();
thread->set_thread_state(state);
Threads_lock->unlock();
break;
default:
fatal(err_msg("Illegal threadstate encountered: %d", state));
}
if (state != _thread_blocked_trans &&
state != _thread_in_vm_trans &&
thread->has_special_runtime_exit_condition()) {
thread->handle_special_runtime_exit_condition(
!thread->is_at_poll_safepoint() && (state != _thread_in_native_trans));
}
}
void SafepointSynchronize::handle_polling_page_exception(JavaThread *thread) {
assert(thread->is_Java_thread(), "polling reference encountered by VM thread");
assert(thread->thread_state() == _thread_in_Java, "should come from Java code");
assert(SafepointSynchronize::is_synchronizing(), "polling encountered outside safepoint synchronization");
if (ShowSafepointMsgs) {
tty->print("handle_polling_page_exception: ");
}
if (PrintSafepointStatistics) {
inc_page_trap_count();
}
ThreadSafepointState* state = thread->safepoint_state();
state->handle_polling_page_exception();
}
void SafepointSynchronize::print_safepoint_timeout(SafepointTimeoutReason reason) {
if (!timeout_error_printed) {
timeout_error_printed = true;
tty->cr();
tty->print_cr("# SafepointSynchronize::begin: Timeout detected:");
if (reason == _spinning_timeout) {
tty->print_cr("# SafepointSynchronize::begin: Timed out while spinning to reach a safepoint.");
} else if (reason == _blocking_timeout) {
tty->print_cr("# SafepointSynchronize::begin: Timed out while waiting for threads to stop.");
}
tty->print_cr("# SafepointSynchronize::begin: Threads which did not reach the safepoint:");
ThreadSafepointState *cur_state;
ResourceMark rm;
for(JavaThread *cur_thread = Threads::first(); cur_thread;
cur_thread = cur_thread->next()) {
cur_state = cur_thread->safepoint_state();
if (cur_thread->thread_state() != _thread_blocked &&
((reason == _spinning_timeout && cur_state->is_running()) ||
(reason == _blocking_timeout && !cur_state->has_called_back()))) {
tty->print("# ");
cur_thread->print();
tty->cr();
}
}
tty->print_cr("# SafepointSynchronize::begin: (End of list)");
}
if (AbortVMOnSafepointTimeout) {
char msg[1024];
VM_Operation *op = VMThread::vm_operation();
sprintf(msg, "Safepoint sync time longer than " INTX_FORMAT "ms detected when executing %s.",
SafepointTimeoutDelay,
op != NULL ? op->name() : "no vm operation");
fatal(msg);
}
}
ThreadSafepointState::ThreadSafepointState(JavaThread *thread) {
_thread = thread;
_type = _running;
_has_called_back = false;
_at_poll_safepoint = false;
}
void ThreadSafepointState::create(JavaThread *thread) {
ThreadSafepointState *state = new ThreadSafepointState(thread);
thread->set_safepoint_state(state);
}
void ThreadSafepointState::destroy(JavaThread *thread) {
if (thread->safepoint_state()) {
delete(thread->safepoint_state());
thread->set_safepoint_state(NULL);
}
}
void ThreadSafepointState::examine_state_of_thread() {
assert(is_running(), "better be running or just have hit safepoint poll");
JavaThreadState state = _thread->thread_state();
_orig_thread_state = state;
bool is_suspended = _thread->is_ext_suspended();
if (is_suspended) {
roll_forward(_at_safepoint);
return;
}
if (SafepointSynchronize::safepoint_safe(_thread, state)) {
SafepointSynchronize::check_for_lazy_critical_native(_thread, state);
roll_forward(_at_safepoint);
return;
}
if (state == _thread_in_vm) {
roll_forward(_call_back);
return;
}
assert(is_running(), "examine_state_of_thread on non-running thread");
return;
}
void ThreadSafepointState::roll_forward(suspend_type type) {
_type = type;
switch(_type) {
case _at_safepoint:
SafepointSynchronize::signal_thread_at_safepoint();
DEBUG_ONLY(_thread->set_visited_for_critical_count(true));
if (_thread->in_critical()) {
SafepointSynchronize::increment_jni_active_count();
}
break;
case _call_back:
set_has_called_back(false);
break;
case _running:
default:
ShouldNotReachHere();
}
}
void ThreadSafepointState::restart() {
switch(type()) {
case _at_safepoint:
case _call_back:
break;
case _running:
default:
tty->print_cr("restart thread " INTPTR_FORMAT " with state %d",
_thread, _type);
_thread->print();
ShouldNotReachHere();
}
_type = _running;
set_has_called_back(false);
}
void ThreadSafepointState::print_on(outputStream *st) const {
const char *s = NULL;
switch(_type) {
case _running : s = "_running"; break;
case _at_safepoint : s = "_at_safepoint"; break;
case _call_back : s = "_call_back"; break;
default:
ShouldNotReachHere();
}
st->print_cr("Thread: " INTPTR_FORMAT
" [0x%2x] State: %s _has_called_back %d _at_poll_safepoint %d",
_thread, _thread->osthread()->thread_id(), s, _has_called_back,
_at_poll_safepoint);
_thread->print_thread_state_on(st);
}
void ThreadSafepointState::handle_polling_page_exception() {
assert(type() == ThreadSafepointState::_running,
"polling page exception on thread not running state");
if (ShowSafepointMsgs && Verbose) {
tty->print_cr("Polling page exception at " INTPTR_FORMAT, thread()->saved_exception_pc());
}
address real_return_addr = thread()->saved_exception_pc();
CodeBlob *cb = CodeCache::find_blob(real_return_addr);
assert(cb != NULL && cb->is_nmethod(), "return address should be in nmethod");
nmethod* nm = (nmethod*)cb;
frame stub_fr = thread()->last_frame();
CodeBlob* stub_cb = stub_fr.cb();
assert(stub_cb->is_safepoint_stub(), "must be a safepoint stub");
RegisterMap map(thread(), true);
frame caller_fr = stub_fr.sender(&map);
assert( nm->is_at_poll_or_poll_return(real_return_addr), "should not be at call" );
if( nm->is_at_poll_return(real_return_addr) ) {
bool return_oop = nm->method()->is_returning_oop();
HandleMark hm(thread());
Handle return_value;
if (return_oop) {
oop result = caller_fr.saved_oop_result(&map);
assert(result == NULL || result->is_oop(), "must be oop");
return_value = Handle(thread(), result);
assert(Universe::heap()->is_in_or_null(result), "must be heap pointer");
}
SafepointSynchronize::block(thread());
if (return_oop) {
caller_fr.set_saved_oop_result(&map, return_value());
}
}
else {
set_at_poll_safepoint(true);
assert(real_return_addr == caller_fr.pc(), "must match");
SafepointSynchronize::block(thread());
set_at_poll_safepoint(false);
if (thread()->has_async_condition()) {
ThreadInVMfromJavaNoAsyncException __tiv(thread());
Deoptimization::deoptimize_frame(thread(), caller_fr.id());
}
if (thread()->has_pending_exception() ) {
RegisterMap map(thread(), true);
frame caller_fr = stub_fr.sender(&map);
if (caller_fr.is_deoptimized_frame()) {
fatal("Exception installed and deoptimization is pending");
}
}
}
}
SafepointSynchronize::SafepointStats* SafepointSynchronize::_safepoint_stats = NULL;
jlong SafepointSynchronize::_safepoint_begin_time = 0;
int SafepointSynchronize::_cur_stat_index = 0;
julong SafepointSynchronize::_safepoint_reasons[VM_Operation::VMOp_Terminating];
julong SafepointSynchronize::_coalesced_vmop_count = 0;
jlong SafepointSynchronize::_max_sync_time = 0;
jlong SafepointSynchronize::_max_vmop_time = 0;
float SafepointSynchronize::_ts_of_current_safepoint = 0.0f;
static jlong cleanup_end_time = 0;
static bool need_to_track_page_armed_status = false;
static bool init_done = false;
static void print_header() {
tty->print(" vmop "
"[threads: total initially_running wait_to_block] ");
tty->print("[time: spin block sync cleanup vmop] ");
if (need_to_track_page_armed_status) {
tty->print("page_armed ");
}
tty->print_cr("page_trap_count");
}
void SafepointSynchronize::deferred_initialize_stat() {
if (init_done) return;
if (PrintSafepointStatisticsCount <= 0) {
fatal("Wrong PrintSafepointStatisticsCount");
}
int stats_array_size;
if (PrintSafepointStatisticsTimeout > 0) {
stats_array_size = 1;
PrintSafepointStatistics = true;
} else {
stats_array_size = PrintSafepointStatisticsCount;
}
_safepoint_stats = (SafepointStats*)os::malloc(stats_array_size
guarantee(_safepoint_stats != NULL,
"not enough memory for safepoint instrumentation data");
if (UseCompilerSafepoints && DeferPollingPageLoopCount >= 0) {
need_to_track_page_armed_status = true;
}
init_done = true;
}
void SafepointSynchronize::begin_statistics(int nof_threads, int nof_running) {
assert(init_done, "safepoint statistics array hasn't been initialized");
SafepointStats *spstat = &_safepoint_stats[_cur_stat_index];
spstat->_time_stamp = _ts_of_current_safepoint;
VM_Operation *op = VMThread::vm_operation();
spstat->_vmop_type = (op != NULL ? op->type() : -1);
if (op != NULL) {
_safepoint_reasons[spstat->_vmop_type]++;
}
spstat->_nof_total_threads = nof_threads;
spstat->_nof_initial_running_threads = nof_running;
spstat->_nof_threads_hit_page_trap = 0;
if (nof_running != 0) {
spstat->_time_to_spin = os::javaTimeNanos();
} else {
spstat->_time_to_spin = 0;
}
}
void SafepointSynchronize::update_statistics_on_spin_end() {
SafepointStats *spstat = &_safepoint_stats[_cur_stat_index];
jlong cur_time = os::javaTimeNanos();
spstat->_nof_threads_wait_to_block = _waiting_to_block;
if (spstat->_nof_initial_running_threads != 0) {
spstat->_time_to_spin = cur_time - spstat->_time_to_spin;
}
if (need_to_track_page_armed_status) {
spstat->_page_armed = (PageArmed == 1);
}
if (_waiting_to_block != 0) {
spstat->_time_to_wait_to_block = cur_time;
} else {
spstat->_time_to_wait_to_block = 0;
}
}
void SafepointSynchronize::update_statistics_on_sync_end(jlong end_time) {
SafepointStats *spstat = &_safepoint_stats[_cur_stat_index];
if (spstat->_nof_threads_wait_to_block != 0) {
spstat->_time_to_wait_to_block = end_time -
spstat->_time_to_wait_to_block;
}
spstat->_time_to_sync = end_time - _safepoint_begin_time;
if (spstat->_time_to_sync > _max_sync_time) {
_max_sync_time = spstat->_time_to_sync;
}
spstat->_time_to_do_cleanups = end_time;
}
void SafepointSynchronize::update_statistics_on_cleanup_end(jlong end_time) {
SafepointStats *spstat = &_safepoint_stats[_cur_stat_index];
spstat->_time_to_do_cleanups = end_time - spstat->_time_to_do_cleanups;
cleanup_end_time = end_time;
}
void SafepointSynchronize::end_statistics(jlong vmop_end_time) {
SafepointStats *spstat = &_safepoint_stats[_cur_stat_index];
spstat->_time_to_exec_vmop = vmop_end_time - cleanup_end_time;
if (spstat->_time_to_exec_vmop > _max_vmop_time) {
_max_vmop_time = spstat->_time_to_exec_vmop;
}
if ( PrintSafepointStatisticsTimeout > 0) {
if (spstat->_time_to_sync > PrintSafepointStatisticsTimeout * MICROUNITS) {
print_statistics();
}
} else {
if (_cur_stat_index == PrintSafepointStatisticsCount - 1) {
print_statistics();
_cur_stat_index = 0;
} else {
_cur_stat_index++;
}
}
}
void SafepointSynchronize::print_statistics() {
SafepointStats* sstats = _safepoint_stats;
for (int index = 0; index <= _cur_stat_index; index++) {
if (index % 30 == 0) {
print_header();
}
sstats = &_safepoint_stats[index];
tty->print("%.3f: ", sstats->_time_stamp);
tty->print("%-26s ["
INT32_FORMAT_W(8) INT32_FORMAT_W(11) INT32_FORMAT_W(15)
" ] ",
sstats->_vmop_type == -1 ? "no vm operation" :
VM_Operation::name(sstats->_vmop_type),
sstats->_nof_total_threads,
sstats->_nof_initial_running_threads,
sstats->_nof_threads_wait_to_block);
tty->print(" ["
INT64_FORMAT_W(6) INT64_FORMAT_W(6)
INT64_FORMAT_W(6) INT64_FORMAT_W(6)
INT64_FORMAT_W(6) " ] ",
sstats->_time_to_spin / MICROUNITS,
sstats->_time_to_wait_to_block / MICROUNITS,
sstats->_time_to_sync / MICROUNITS,
sstats->_time_to_do_cleanups / MICROUNITS,
sstats->_time_to_exec_vmop / MICROUNITS);
if (need_to_track_page_armed_status) {
tty->print(INT32_FORMAT " ", sstats->_page_armed);
}
tty->print_cr(INT32_FORMAT " ", sstats->_nof_threads_hit_page_trap);
}
}
void SafepointSynchronize::print_stat_on_exit() {
if (_safepoint_stats == NULL) return;
SafepointStats *spstat = &_safepoint_stats[_cur_stat_index];
_safepoint_stats[_cur_stat_index]._time_to_exec_vmop =
os::javaTimeNanos() - cleanup_end_time;
if ( PrintSafepointStatisticsTimeout < 0 ||
spstat->_time_to_sync > PrintSafepointStatisticsTimeout * MICROUNITS) {
print_statistics();
}
tty->cr();
if (!need_to_track_page_armed_status) {
if (UseCompilerSafepoints) {
tty->print_cr("Polling page always armed");
}
} else {
tty->print_cr("Defer polling page loop count = %d\n",
DeferPollingPageLoopCount);
}
for (int index = 0; index < VM_Operation::VMOp_Terminating; index++) {
if (_safepoint_reasons[index] != 0) {
tty->print_cr("%-26s" UINT64_FORMAT_W(10), VM_Operation::name(index),
_safepoint_reasons[index]);
}
}
tty->print_cr(UINT64_FORMAT_W(5) " VM operations coalesced during safepoint",
_coalesced_vmop_count);
tty->print_cr("Maximum sync time " INT64_FORMAT_W(5) " ms",
_max_sync_time / MICROUNITS);
tty->print_cr("Maximum vm operation time (except for Exit VM operation) "
INT64_FORMAT_W(5) " ms",
_max_vmop_time / MICROUNITS);
}
#ifndef PRODUCT
void SafepointSynchronize::print_state() {
if (_state == _not_synchronized) {
tty->print_cr("not synchronized");
} else if (_state == _synchronizing || _state == _synchronized) {
tty->print_cr("State: %s", (_state == _synchronizing) ? "synchronizing" :
"synchronized");
for(JavaThread *cur = Threads::first(); cur; cur = cur->next()) {
cur->safepoint_state()->print();
}
}
}
void SafepointSynchronize::safepoint_msg(const char* format, ...) {
if (ShowSafepointMsgs) {
va_list ap;
va_start(ap, format);
tty->vprint_cr(format, ap);
va_end(ap);
}
}
#endif // !PRODUCT
C:\hotspot-69087d08d473\src\share\vm/runtime/safepoint.hpp
#ifndef SHARE_VM_RUNTIME_SAFEPOINT_HPP
#define SHARE_VM_RUNTIME_SAFEPOINT_HPP
#include "asm/assembler.hpp"
#include "code/nmethod.hpp"
#include "memory/allocation.hpp"
#include "runtime/extendedPC.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/os.hpp"
#include "utilities/ostream.hpp"
class ThreadSafepointState;
class SnippetCache;
class nmethod;
class SafepointSynchronize : AllStatic {
public:
enum SynchronizeState {
_not_synchronized = 0, // Threads not synchronized at a safepoint
_synchronizing = 1, // Synchronizing in progress
_synchronized = 2 // All Java threads are stopped at a safepoint. Only VM thread is running
};
enum SafepointingThread {
_null_thread = 0,
_vm_thread = 1,
_other_thread = 2
};
enum SafepointTimeoutReason {
_spinning_timeout = 0,
_blocking_timeout = 1
};
typedef struct {
float _time_stamp; // record when the current safepoint occurs in seconds
int _vmop_type; // type of VM operation triggers the safepoint
int _nof_total_threads; // total number of Java threads
int _nof_initial_running_threads; // total number of initially seen running threads
int _nof_threads_wait_to_block; // total number of threads waiting for to block
bool _page_armed; // true if polling page is armed, false otherwise
int _nof_threads_hit_page_trap; // total number of threads hitting the page trap
jlong _time_to_spin; // total time in millis spent in spinning
jlong _time_to_wait_to_block; // total time in millis spent in waiting for to block
jlong _time_to_do_cleanups; // total time in millis spent in performing cleanups
jlong _time_to_sync; // total time in millis spent in getting to _synchronized
jlong _time_to_exec_vmop; // total time in millis spent in vm operation itself
} SafepointStats;
private:
static volatile SynchronizeState _state; // Threads might read this flag directly, without acquireing the Threads_lock
static volatile int _waiting_to_block; // number of threads we are waiting for to block
static int _current_jni_active_count; // Counts the number of active critical natives during the safepoint
public:
static volatile int _safepoint_counter;
private:
static long _end_of_last_safepoint; // Time of last safepoint in milliseconds
static jlong _safepoint_begin_time; // time when safepoint begins
static SafepointStats* _safepoint_stats; // array of SafepointStats struct
static int _cur_stat_index; // current index to the above array
static julong _safepoint_reasons[]; // safepoint count for each VM op
static julong _coalesced_vmop_count; // coalesced vmop count
static jlong _max_sync_time; // maximum sync time in nanos
static jlong _max_vmop_time; // maximum vm operation time in nanos
static float _ts_of_current_safepoint; // time stamp of current safepoint in seconds
static void begin_statistics(int nof_threads, int nof_running);
static void update_statistics_on_spin_end();
static void update_statistics_on_sync_end(jlong end_time);
static void update_statistics_on_cleanup_end(jlong end_time);
static void end_statistics(jlong end_time);
static void print_statistics();
inline static void inc_page_trap_count() {
Atomic::inc(&_safepoint_stats[_cur_stat_index]._nof_threads_hit_page_trap);
}
static void print_safepoint_timeout(SafepointTimeoutReason timeout_reason);
public:
static void begin();
static void end(); // Start all suspended threads again...
static bool safepoint_safe(JavaThread *thread, JavaThreadState state);
static void check_for_lazy_critical_native(JavaThread *thread, JavaThreadState state);
inline static bool is_at_safepoint() { return _state == _synchronized; }
inline static bool is_synchronizing() { return _state == _synchronizing; }
inline static int safepoint_counter() { return _safepoint_counter; }
inline static bool do_call_back() {
return (_state != _not_synchronized);
}
inline static void increment_jni_active_count() {
assert_locked_or_safepoint(Safepoint_lock);
_current_jni_active_count++;
}
static void block(JavaThread *thread);
static void signal_thread_at_safepoint() { _waiting_to_block--; }
static void handle_polling_page_exception(JavaThread *thread);
static long last_non_safepoint_interval() {
return os::javaTimeMillis() - _end_of_last_safepoint;
}
static long end_of_last_safepoint() {
return _end_of_last_safepoint;
}
static bool is_cleanup_needed();
static void do_cleanup_tasks();
static void print_state() PRODUCT_RETURN;
static void safepoint_msg(const char* format, ...) ATTRIBUTE_PRINTF(1, 2) PRODUCT_RETURN;
static void deferred_initialize_stat();
static void print_stat_on_exit();
inline static void inc_vmop_coalesced_count() { _coalesced_vmop_count++; }
static void set_is_at_safepoint() { _state = _synchronized; }
static void set_is_not_at_safepoint() { _state = _not_synchronized; }
static address address_of_state() { return (address)&_state; }
static address safepoint_counter_addr() { return (address)&_safepoint_counter; }
};
class ThreadSafepointState: public CHeapObj<mtThread> {
public:
enum suspend_type {
_running = 0, // Thread state not yet determined (i.e., not at a safepoint yet)
_at_safepoint = 1, // Thread at a safepoint (f.ex., when blocked on a lock)
_call_back = 2 // Keep executing and wait for callback (if thread is in interpreted or vm)
};
private:
volatile bool _at_poll_safepoint; // At polling page safepoint (NOT a poll return safepoint)
bool _has_called_back;
JavaThread * _thread;
volatile suspend_type _type;
JavaThreadState _orig_thread_state;
public:
ThreadSafepointState(JavaThread *thread);
void examine_state_of_thread();
void roll_forward(suspend_type type);
void restart();
JavaThread* thread() const { return _thread; }
suspend_type type() const { return _type; }
bool is_running() const { return (_type==_running); }
JavaThreadState orig_thread_state() const { return _orig_thread_state; }
bool has_called_back() const { return _has_called_back; }
void set_has_called_back(bool val) { _has_called_back = val; }
bool is_at_poll_safepoint() { return _at_poll_safepoint; }
void set_at_poll_safepoint(bool val) { _at_poll_safepoint = val; }
void handle_polling_page_exception();
void print_on(outputStream* st) const;
void print() const { print_on(tty); }
static void create(JavaThread *thread);
static void destroy(JavaThread *thread);
void safepoint_msg(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) {
if (ShowSafepointMsgs) {
va_list ap;
va_start(ap, format);
tty->vprint_cr(format, ap);
va_end(ap);
}
}
};
#endif // SHARE_VM_RUNTIME_SAFEPOINT_HPP
C:\hotspot-69087d08d473\src\share\vm/runtime/semaphore.hpp
#ifndef SHARE_VM_RUNTIME_SEMAPHORE_HPP
#define SHARE_VM_RUNTIME_SEMAPHORE_HPP
#include "memory/allocation.hpp"
#if defined(LINUX) || defined(SOLARIS) || defined(AIX)
# include "semaphore_posix.hpp"
#elif defined(BSD)
# include "semaphore_bsd.hpp"
#elif defined(_WINDOWS)
# include "semaphore_windows.hpp"
#else
# error "No semaphore implementation provided for this OS"
#endif
class JavaThread;
class Semaphore : public CHeapObj<mtInternal> {
SemaphoreImpl _impl;
Semaphore(const Semaphore&);
Semaphore& operator=(const Semaphore&);
public:
Semaphore(uint value = 0) : _impl(value) {}
~Semaphore() {}
void signal(uint count = 1) { _impl.signal(count); }
void wait() { _impl.wait(); }
bool trywait() { return _impl.trywait(); }
void wait_with_safepoint_check(JavaThread* thread);
};
#endif // SHARE_VM_RUNTIME_SEMAPHORE_HPP
C:\hotspot-69087d08d473\src\share\vm/runtime/semaphore.inline.hpp
#ifndef SHARE_VM_RUNTIME_SEMAPHORE_INLINE_HPP
#define SHARE_VM_RUNTIME_SEMAPHORE_INLINE_HPP
#include "runtime/interfaceSupport.inline.hpp"
#include "runtime/semaphore.hpp"
#include "runtime/thread.inline.hpp"
inline void Semaphore::wait_with_safepoint_check(JavaThread* thread) {
ThreadBlockInVM tbivm(thread);
OSThreadWaitState osts(thread->osthread(), false /* not in Object.wait() */);
_impl.wait();
}
#endif // SHARE_VM_RUNTIME_SEMAPHORE_INLINE_HPP
C:\hotspot-69087d08d473\src\share\vm/runtime/serviceThread.cpp
#include "precompiled.hpp"
#include "runtime/interfaceSupport.hpp"
#include "runtime/javaCalls.hpp"
#include "runtime/serviceThread.hpp"
#include "runtime/mutexLocker.hpp"
#include "prims/jvmtiImpl.hpp"
#include "services/allocationContextService.hpp"
#include "services/gcNotifier.hpp"
#include "services/diagnosticArgument.hpp"
#include "services/diagnosticFramework.hpp"
ServiceThread* ServiceThread::_instance = NULL;
void ServiceThread::initialize() {
EXCEPTION_MARK;
instanceKlassHandle klass (THREAD, SystemDictionary::Thread_klass());
instanceHandle thread_oop = klass->allocate_instance_handle(CHECK);
const char* name = JDK_Version::is_gte_jdk17x_version() ?
"Service Thread" : "Low Memory Detector";
Handle string = java_lang_String::create_from_str(name, CHECK);
Handle thread_group (THREAD, Universe::system_thread_group());
JavaValue result(T_VOID);
JavaCalls::call_special(&result, thread_oop,
klass,
vmSymbols::object_initializer_name(),
vmSymbols::threadgroup_string_void_signature(),
thread_group,
string,
CHECK);
{
MutexLocker mu(Threads_lock);
ServiceThread* thread = new ServiceThread(&service_thread_entry);
if (thread == NULL || thread->osthread() == NULL) {
vm_exit_during_initialization("java.lang.OutOfMemoryError",
"unable to create new native thread");
}
java_lang_Thread::set_thread(thread_oop(), thread);
java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
java_lang_Thread::set_daemon(thread_oop());
thread->set_threadObj(thread_oop());
_instance = thread;
Threads::add(thread);
Thread::start(thread);
}
}
void ServiceThread::service_thread_entry(JavaThread* jt, TRAPS) {
while (true) {
bool sensors_changed = false;
bool has_jvmti_events = false;
bool has_gc_notification_event = false;
bool has_dcmd_notification_event = false;
bool acs_notify = false;
JvmtiDeferredEvent jvmti_event;
{
ThreadBlockInVM tbivm(jt);
MutexLockerEx ml(Service_lock, Mutex::_no_safepoint_check_flag);
while (!(sensors_changed = LowMemoryDetector::has_pending_requests()) &&
!(has_jvmti_events = JvmtiDeferredEventQueue::has_events()) &&
!(has_gc_notification_event = GCNotifier::has_event()) &&
!(has_dcmd_notification_event = DCmdFactory::has_pending_jmx_notification()) &&
!(acs_notify = AllocationContextService::should_notify())) {
Service_lock->wait(Mutex::_no_safepoint_check_flag);
}
if (has_jvmti_events) {
jvmti_event = JvmtiDeferredEventQueue::dequeue();
}
}
if (has_jvmti_events) {
jvmti_event.post();
}
if (sensors_changed) {
LowMemoryDetector::process_sensor_changes(jt);
}
if(has_gc_notification_event) {
GCNotifier::sendNotification(CHECK);
}
if(has_dcmd_notification_event) {
DCmdFactory::send_notification(CHECK);
}
if (acs_notify) {
AllocationContextService::notify(CHECK);
}
}
}
bool ServiceThread::is_service_thread(Thread* thread) {
return thread == _instance;
}
C:\hotspot-69087d08d473\src\share\vm/runtime/serviceThread.hpp
#ifndef SHARE_VM_RUNTIME_SERVICETHREAD_HPP
#define SHARE_VM_RUNTIME_SERVICETHREAD_HPP
#include "runtime/thread.hpp"
class ServiceThread : public JavaThread {
friend class VMStructs;
private:
static ServiceThread* _instance;
static void service_thread_entry(JavaThread* thread, TRAPS);
ServiceThread(ThreadFunction entry_point) : JavaThread(entry_point) {};
public:
static void initialize();
bool is_hidden_from_external_view() const { return true; }
static bool is_service_thread(Thread* thread);
};
#endif // SHARE_VM_RUNTIME_SERVICETHREAD_HPP
C:\hotspot-69087d08d473\src\share\vm/runtime/sharedRuntime.cpp
#include "precompiled.hpp"
#include "classfile/systemDictionary.hpp"
#include "classfile/vmSymbols.hpp"
#include "code/compiledIC.hpp"
#include "code/scopeDesc.hpp"
#include "code/vtableStubs.hpp"
#include "compiler/abstractCompiler.hpp"
#include "compiler/compileBroker.hpp"
#include "compiler/compilerOracle.hpp"
#include "compiler/disassembler.hpp"
#include "interpreter/interpreter.hpp"
#include "interpreter/interpreterRuntime.hpp"
#include "memory/gcLocker.inline.hpp"
#include "memory/universe.inline.hpp"
#include "oops/oop.inline.hpp"
#include "prims/forte.hpp"
#include "prims/jvmtiExport.hpp"
#include "prims/jvmtiRedefineClassesTrace.hpp"
#include "prims/methodHandles.hpp"
#include "prims/nativeLookup.hpp"
#include "runtime/arguments.hpp"
#include "runtime/biasedLocking.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/init.hpp"
#include "runtime/interfaceSupport.hpp"
#include "runtime/javaCalls.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/vframe.hpp"
#include "runtime/vframeArray.hpp"
#include "utilities/copy.hpp"
#include "utilities/dtrace.hpp"
#include "utilities/events.hpp"
#include "utilities/hashtable.inline.hpp"
#include "utilities/macros.hpp"
#include "utilities/xmlstream.hpp"
#ifdef TARGET_ARCH_x86
# include "nativeInst_x86.hpp"
# include "vmreg_x86.inline.hpp"
#endif
#ifdef TARGET_ARCH_aarch64
# include "nativeInst_aarch64.hpp"
# include "vmreg_aarch64.inline.hpp"
#endif
#ifdef TARGET_ARCH_sparc
# include "nativeInst_sparc.hpp"
# include "vmreg_sparc.inline.hpp"
#endif
#ifdef TARGET_ARCH_zero
# include "nativeInst_zero.hpp"
# include "vmreg_zero.inline.hpp"
#endif
#ifdef TARGET_ARCH_arm
# include "nativeInst_arm.hpp"
# include "vmreg_arm.inline.hpp"
#endif
#ifdef TARGET_ARCH_ppc
# include "nativeInst_ppc.hpp"
# include "vmreg_ppc.inline.hpp"
#endif
#ifdef COMPILER1
#include "c1/c1_Runtime1.hpp"
#endif
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
RuntimeStub* SharedRuntime::_wrong_method_blob;
RuntimeStub* SharedRuntime::_wrong_method_abstract_blob;
RuntimeStub* SharedRuntime::_ic_miss_blob;
RuntimeStub* SharedRuntime::_resolve_opt_virtual_call_blob;
RuntimeStub* SharedRuntime::_resolve_virtual_call_blob;
RuntimeStub* SharedRuntime::_resolve_static_call_blob;
DeoptimizationBlob* SharedRuntime::_deopt_blob;
SafepointBlob* SharedRuntime::_polling_page_vectors_safepoint_handler_blob;
SafepointBlob* SharedRuntime::_polling_page_safepoint_handler_blob;
SafepointBlob* SharedRuntime::_polling_page_return_handler_blob;
#ifdef COMPILER2
UncommonTrapBlob* SharedRuntime::_uncommon_trap_blob;
#endif // COMPILER2
void SharedRuntime::generate_stubs() {
_wrong_method_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method), "wrong_method_stub");
_wrong_method_abstract_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method_abstract), "wrong_method_abstract_stub");
_ic_miss_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method_ic_miss), "ic_miss_stub");
_resolve_opt_virtual_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_opt_virtual_call_C), "resolve_opt_virtual_call");
_resolve_virtual_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_virtual_call_C), "resolve_virtual_call");
_resolve_static_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_static_call_C), "resolve_static_call");
#ifdef COMPILER2
if (is_wide_vector(MaxVectorSize)) {
_polling_page_vectors_safepoint_handler_blob = generate_handler_blob(CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception), POLL_AT_VECTOR_LOOP);
}
#endif // COMPILER2
_polling_page_safepoint_handler_blob = generate_handler_blob(CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception), POLL_AT_LOOP);
_polling_page_return_handler_blob = generate_handler_blob(CAST_FROM_FN_PTR(address, SafepointSynchronize::handle_polling_page_exception), POLL_AT_RETURN);
generate_deopt_blob();
#ifdef COMPILER2
generate_uncommon_trap_blob();
#endif // COMPILER2
}
#include <math.h>
#ifndef USDT2
HS_DTRACE_PROBE_DECL4(hotspot, object__alloc, Thread*, char*, int, size_t);
HS_DTRACE_PROBE_DECL7(hotspot, method__entry, int,
char*, int, char*, int, char*, int);
HS_DTRACE_PROBE_DECL7(hotspot, method__return, int,
char*, int, char*, int, char*, int);
#endif /* !USDT2 */
#ifndef PRODUCT
int SharedRuntime::_ic_miss_ctr = 0;
int SharedRuntime::_wrong_method_ctr = 0;
int SharedRuntime::_resolve_static_ctr = 0;
int SharedRuntime::_resolve_virtual_ctr = 0;
int SharedRuntime::_resolve_opt_virtual_ctr = 0;
int SharedRuntime::_implicit_null_throws = 0;
int SharedRuntime::_implicit_div0_throws = 0;
int SharedRuntime::_throw_null_ctr = 0;
int SharedRuntime::_nof_normal_calls = 0;
int SharedRuntime::_nof_optimized_calls = 0;
int SharedRuntime::_nof_inlined_calls = 0;
int SharedRuntime::_nof_megamorphic_calls = 0;
int SharedRuntime::_nof_static_calls = 0;
int SharedRuntime::_nof_inlined_static_calls = 0;
int SharedRuntime::_nof_interface_calls = 0;
int SharedRuntime::_nof_optimized_interface_calls = 0;
int SharedRuntime::_nof_inlined_interface_calls = 0;
int SharedRuntime::_nof_megamorphic_interface_calls = 0;
int SharedRuntime::_nof_removable_exceptions = 0;
int SharedRuntime::_new_instance_ctr=0;
int SharedRuntime::_new_array_ctr=0;
int SharedRuntime::_multi1_ctr=0;
int SharedRuntime::_multi2_ctr=0;
int SharedRuntime::_multi3_ctr=0;
int SharedRuntime::_multi4_ctr=0;
int SharedRuntime::_multi5_ctr=0;
int SharedRuntime::_mon_enter_stub_ctr=0;
int SharedRuntime::_mon_exit_stub_ctr=0;
int SharedRuntime::_mon_enter_ctr=0;
int SharedRuntime::_mon_exit_ctr=0;
int SharedRuntime::_partial_subtype_ctr=0;
int SharedRuntime::_jbyte_array_copy_ctr=0;
int SharedRuntime::_jshort_array_copy_ctr=0;
int SharedRuntime::_jint_array_copy_ctr=0;
int SharedRuntime::_jlong_array_copy_ctr=0;
int SharedRuntime::_oop_array_copy_ctr=0;
int SharedRuntime::_checkcast_array_copy_ctr=0;
int SharedRuntime::_unsafe_array_copy_ctr=0;
int SharedRuntime::_generic_array_copy_ctr=0;
int SharedRuntime::_slow_array_copy_ctr=0;
int SharedRuntime::_find_handler_ctr=0;
int SharedRuntime::_rethrow_ctr=0;
int SharedRuntime::_ICmiss_index = 0;
int SharedRuntime::_ICmiss_count[SharedRuntime::maxICmiss_count];
address SharedRuntime::_ICmiss_at[SharedRuntime::maxICmiss_count];
void SharedRuntime::trace_ic_miss(address at) {
for (int i = 0; i < _ICmiss_index; i++) {
if (_ICmiss_at[i] == at) {
_ICmiss_count[i]++;
return;
}
}
int index = _ICmiss_index++;
if (_ICmiss_index >= maxICmiss_count) _ICmiss_index = maxICmiss_count - 1;
_ICmiss_at[index] = at;
_ICmiss_count[index] = 1;
}
void SharedRuntime::print_ic_miss_histogram() {
if (ICMissHistogram) {
tty->print_cr ("IC Miss Histogram:");
int tot_misses = 0;
for (int i = 0; i < _ICmiss_index; i++) {
tty->print_cr(" at: " INTPTR_FORMAT " nof: %d", _ICmiss_at[i], _ICmiss_count[i]);
tot_misses += _ICmiss_count[i];
}
tty->print_cr ("Total IC misses: %7d", tot_misses);
}
}
#endif // PRODUCT
#if INCLUDE_ALL_GCS
JRT_LEAF(void, SharedRuntime::g1_wb_pre(oopDesc* orig, JavaThread *thread))
if (orig == NULL) {
assert(false, "should be optimized out");
return;
}
assert(orig->is_oop(true /* ignore mark word */), "Error");
thread->satb_mark_queue().enqueue(orig);
JRT_END
JRT_LEAF(void, SharedRuntime::g1_wb_post(void* card_addr, JavaThread* thread))
thread->dirty_card_queue().enqueue(card_addr);
JRT_END
#endif // INCLUDE_ALL_GCS
JRT_LEAF(jlong, SharedRuntime::lmul(jlong y, jlong x))
return x * y;
JRT_END
JRT_LEAF(jlong, SharedRuntime::ldiv(jlong y, jlong x))
if (x == min_jlong && y == CONST64(-1)) {
return x;
} else {
return x / y;
}
JRT_END
JRT_LEAF(jlong, SharedRuntime::lrem(jlong y, jlong x))
if (x == min_jlong && y == CONST64(-1)) {
return 0;
} else {
return x % y;
}
JRT_END
const juint float_sign_mask = 0x7FFFFFFF;
const juint float_infinity = 0x7F800000;
const julong double_sign_mask = CONST64(0x7FFFFFFFFFFFFFFF);
const julong double_infinity = CONST64(0x7FF0000000000000);
JRT_LEAF(jfloat, SharedRuntime::frem(jfloat x, jfloat y))
#ifdef _WIN64
union { jfloat f; juint i; } xbits, ybits;
xbits.f = x;
ybits.f = y;
if ( ((xbits.i & float_sign_mask) != float_infinity) &&
((ybits.i & float_sign_mask) == float_infinity) ) {
return x;
}
#endif
return ((jfloat)fmod((double)x,(double)y));
JRT_END
JRT_LEAF(jdouble, SharedRuntime::drem(jdouble x, jdouble y))
#ifdef _WIN64
union { jdouble d; julong l; } xbits, ybits;
xbits.d = x;
ybits.d = y;
if ( ((xbits.l & double_sign_mask) != double_infinity) &&
((ybits.l & double_sign_mask) == double_infinity) ) {
return x;
}
#endif
return ((jdouble)fmod((double)x,(double)y));
JRT_END
#ifdef __SOFTFP__
JRT_LEAF(jfloat, SharedRuntime::fadd(jfloat x, jfloat y))
return x + y;
JRT_END
JRT_LEAF(jfloat, SharedRuntime::fsub(jfloat x, jfloat y))
return x - y;
JRT_END
JRT_LEAF(jfloat, SharedRuntime::fmul(jfloat x, jfloat y))
return x * y;
JRT_END
JRT_LEAF(jfloat, SharedRuntime::fdiv(jfloat x, jfloat y))
return x / y;
JRT_END
JRT_LEAF(jdouble, SharedRuntime::dadd(jdouble x, jdouble y))
return x + y;
JRT_END
JRT_LEAF(jdouble, SharedRuntime::dsub(jdouble x, jdouble y))
return x - y;
JRT_END
JRT_LEAF(jdouble, SharedRuntime::dmul(jdouble x, jdouble y))
return x * y;
JRT_END
JRT_LEAF(jdouble, SharedRuntime::ddiv(jdouble x, jdouble y))
return x / y;
JRT_END
JRT_LEAF(jfloat, SharedRuntime::i2f(jint x))
return (jfloat)x;
JRT_END
JRT_LEAF(jdouble, SharedRuntime::i2d(jint x))
return (jdouble)x;
JRT_END
JRT_LEAF(jdouble, SharedRuntime::f2d(jfloat x))
return (jdouble)x;
JRT_END
JRT_LEAF(int, SharedRuntime::fcmpl(float x, float y))
return x>y ? 1 : (x==y ? 0 : -1); /* x<y or is_nan*/
JRT_END
JRT_LEAF(int, SharedRuntime::fcmpg(float x, float y))
return x<y ? -1 : (x==y ? 0 : 1); /* x>y or is_nan */
JRT_END
JRT_LEAF(int, SharedRuntime::dcmpl(double x, double y))
return x>y ? 1 : (x==y ? 0 : -1); /* x<y or is_nan */
JRT_END
JRT_LEAF(int, SharedRuntime::dcmpg(double x, double y))
return x<y ? -1 : (x==y ? 0 : 1); /* x>y or is_nan */
JRT_END
JRT_LEAF(int, SharedRuntime::unordered_fcmplt(float x, float y))
return (x < y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
JRT_LEAF(int, SharedRuntime::unordered_dcmplt(double x, double y))
return (x < y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
JRT_LEAF(int, SharedRuntime::unordered_fcmple(float x, float y))
return (x <= y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
JRT_LEAF(int, SharedRuntime::unordered_dcmple(double x, double y))
return (x <= y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
JRT_LEAF(int, SharedRuntime::unordered_fcmpge(float x, float y))
return (x >= y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
JRT_LEAF(int, SharedRuntime::unordered_dcmpge(double x, double y))
return (x >= y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
JRT_LEAF(int, SharedRuntime::unordered_fcmpgt(float x, float y))
return (x > y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
JRT_LEAF(int, SharedRuntime::unordered_dcmpgt(double x, double y))
return (x > y) ? 1 : ((g_isnan(x) || g_isnan(y)) ? 1 : 0);
JRT_END
float SharedRuntime::fneg(float f) {
return -f;
}
double SharedRuntime::dneg(double f) {
return -f;
}
#endif // __SOFTFP__
#if defined(__SOFTFP__) || defined(E500V2)
double SharedRuntime::dabs(double f) {
return (f <= (double)0.0) ? (double)0.0 - f : f;
}
#endif
#if defined(__SOFTFP__) || defined(PPC32)
double SharedRuntime::dsqrt(double f) {
return sqrt(f);
}
#endif
JRT_LEAF(jint, SharedRuntime::f2i(jfloat x))
if (g_isnan(x))
return 0;
if (x >= (jfloat) max_jint)
return max_jint;
if (x <= (jfloat) min_jint)
return min_jint;
return (jint) x;
JRT_END
JRT_LEAF(jlong, SharedRuntime::f2l(jfloat x))
if (g_isnan(x))
return 0;
if (x >= (jfloat) max_jlong)
return max_jlong;
if (x <= (jfloat) min_jlong)
return min_jlong;
return (jlong) x;
JRT_END
JRT_LEAF(jint, SharedRuntime::d2i(jdouble x))
if (g_isnan(x))
return 0;
if (x >= (jdouble) max_jint)
return max_jint;
if (x <= (jdouble) min_jint)
return min_jint;
return (jint) x;
JRT_END
JRT_LEAF(jlong, SharedRuntime::d2l(jdouble x))
if (g_isnan(x))
return 0;
if (x >= (jdouble) max_jlong)
return max_jlong;
if (x <= (jdouble) min_jlong)
return min_jlong;
return (jlong) x;
JRT_END
JRT_LEAF(jfloat, SharedRuntime::d2f(jdouble x))
return (jfloat)x;
JRT_END
JRT_LEAF(jfloat, SharedRuntime::l2f(jlong x))
return (jfloat)x;
JRT_END
JRT_LEAF(jdouble, SharedRuntime::l2d(jlong x))
return (jdouble)x;
JRT_END
address SharedRuntime::raw_exception_handler_for_return_address(JavaThread* thread, address return_address) {
assert(frame::verify_return_pc(return_address), err_msg("must be a return address: " INTPTR_FORMAT, return_address));
assert(thread->frames_to_pop_failed_realloc() == 0 || Interpreter::contains(return_address), "missed frames to pop?");
thread->set_is_method_handle_return(false);
CodeBlob* blob = CodeCache::find_blob(return_address);
nmethod* nm = (blob != NULL) ? blob->as_nmethod_or_null() : NULL;
if (nm != NULL) {
thread->set_is_method_handle_return(nm->is_method_handle_return(return_address));
assert(!nm->is_native_method(), "no exception handler");
assert(nm->header_begin() != nm->exception_begin(), "no exception handler");
if (nm->is_deopt_pc(return_address)) {
bool guard_pages_enabled = thread->stack_yellow_zone_enabled();
if (!guard_pages_enabled) guard_pages_enabled = thread->reguard_stack();
assert(guard_pages_enabled, "stack banging in deopt blob may cause crash");
return SharedRuntime::deopt_blob()->unpack_with_exception();
} else {
return nm->exception_begin();
}
}
if (StubRoutines::returns_to_call_stub(return_address)) {
return StubRoutines::catch_exception_entry();
}
if (Interpreter::contains(return_address)) {
return Interpreter::rethrow_exception_entry();
}
guarantee(blob == NULL || !blob->is_runtime_stub(), "caller should have skipped stub");
guarantee(!VtableStubs::contains(return_address), "NULL exceptions in vtables should have been handled already!");
#ifndef PRODUCT
{ ResourceMark rm;
tty->print_cr("No exception handler found for exception at " INTPTR_FORMAT " - potential problems:", return_address);
tty->print_cr("a) exception happened in (new?) code stubs/buffers that is not handled here");
tty->print_cr("b) other problem");
}
#endif // PRODUCT
ShouldNotReachHere();
return NULL;
}
JRT_LEAF(address, SharedRuntime::exception_handler_for_return_address(JavaThread* thread, address return_address))
return raw_exception_handler_for_return_address(thread, return_address);
JRT_END
address SharedRuntime::get_poll_stub(address pc) {
address stub;
CodeBlob *cb = CodeCache::find_blob(pc);
guarantee(cb != NULL && cb->is_nmethod(), "safepoint polling: pc must refer to an nmethod");
assert( ((nmethod*)cb)->is_at_poll_or_poll_return(pc),
"safepoint polling: type must be poll" );
assert( ((NativeInstruction*)pc)->is_safepoint_poll(),
"Only polling locations are used for safepoint");
bool at_poll_return = ((nmethod*)cb)->is_at_poll_return(pc);
bool has_wide_vectors = ((nmethod*)cb)->has_wide_vectors();
if (at_poll_return) {
assert(SharedRuntime::polling_page_return_handler_blob() != NULL,
"polling page return stub not created yet");
stub = SharedRuntime::polling_page_return_handler_blob()->entry_point();
} else if (has_wide_vectors) {
assert(SharedRuntime::polling_page_vectors_safepoint_handler_blob() != NULL,
"polling page vectors safepoint stub not created yet");
stub = SharedRuntime::polling_page_vectors_safepoint_handler_blob()->entry_point();
} else {
assert(SharedRuntime::polling_page_safepoint_handler_blob() != NULL,
"polling page safepoint stub not created yet");
stub = SharedRuntime::polling_page_safepoint_handler_blob()->entry_point();
}
#ifndef PRODUCT
if( TraceSafepoint ) {
char buf[256];
jio_snprintf(buf, sizeof(buf),
"... found polling page %s exception at pc = "
INTPTR_FORMAT ", stub =" INTPTR_FORMAT,
at_poll_return ? "return" : "loop",
(intptr_t)pc, (intptr_t)stub);
tty->print_raw_cr(buf);
}
#endif // PRODUCT
return stub;
}
oop SharedRuntime::retrieve_receiver( Symbol* sig, frame caller ) {
assert(caller.is_interpreted_frame(), "");
int args_size = ArgumentSizeComputer(sig).size() + 1;
assert(args_size <= caller.interpreter_frame_expression_stack_size(), "receiver must be on interpreter stack");
oop result = cast_to_oop(*caller.interpreter_frame_tos_at(args_size - 1));
assert(Universe::heap()->is_in(result) && result->is_oop(), "receiver must be an oop");
return result;
}
void SharedRuntime::throw_and_post_jvmti_exception(JavaThread *thread, Handle h_exception) {
if (JvmtiExport::can_post_on_exceptions()) {
vframeStream vfst(thread, true);
methodHandle method = methodHandle(thread, vfst.method());
address bcp = method()->bcp_from(vfst.bci());
JvmtiExport::post_exception_throw(thread, method(), bcp, h_exception());
}
Exceptions::_throw(thread, __FILE__, __LINE__, h_exception);
}
void SharedRuntime::throw_and_post_jvmti_exception(JavaThread *thread, Symbol* name, const char *message) {
Handle h_exception = Exceptions::new_exception(thread, name, message);
throw_and_post_jvmti_exception(thread, h_exception);
}
JRT_LEAF(int, SharedRuntime::rc_trace_method_entry(
JavaThread* thread, Method* method))
assert(RC_TRACE_IN_RANGE(0x00001000, 0x00002000), "wrong call");
if (method->is_obsolete()) {
RC_TRACE_WITH_THREAD(0x00001000, thread,
("calling obsolete method '%s'",
method->name_and_sig_as_C_string()));
if (RC_TRACE_ENABLED(0x00002000)) {
guarantee(false, "faulting at call to an obsolete method.");
}
}
return 0;
JRT_END
address SharedRuntime::compute_compiled_exc_handler(nmethod* nm, address ret_pc, Handle& exception,
bool force_unwind, bool top_frame_only, bool& recursive_exception_occurred) {
assert(nm != NULL, "must exist");
ResourceMark rm;
ScopeDesc* sd = nm->scope_desc_at(ret_pc);
EXCEPTION_MARK;
int handler_bci = -1;
int scope_depth = 0;
if (!force_unwind) {
int bci = sd->bci();
bool recursive_exception = false;
do {
bool skip_scope_increment = false;
KlassHandle ek (THREAD, exception->klass());
methodHandle mh(THREAD, sd->method());
handler_bci = Method::fast_exception_handler_bci_for(mh, ek, bci, THREAD);
if (HAS_PENDING_EXCEPTION) {
recursive_exception = true;
recursive_exception_occurred = true;
exception = Handle(THREAD, PENDING_EXCEPTION);
CLEAR_PENDING_EXCEPTION;
if (handler_bci >= 0) {
bci = handler_bci;
handler_bci = -1;
skip_scope_increment = true;
}
}
else {
recursive_exception = false;
}
if (!top_frame_only && handler_bci < 0 && !skip_scope_increment) {
sd = sd->sender();
if (sd != NULL) {
bci = sd->bci();
}
++scope_depth;
}
} while (recursive_exception || (!top_frame_only && handler_bci < 0 && sd != NULL));
}
int catch_pco = ret_pc - nm->code_begin();
ExceptionHandlerTable table(nm);
HandlerTableEntry *t = table.entry_for(catch_pco, handler_bci, scope_depth);
if (t == NULL && (nm->is_compiled_by_c1() || handler_bci != -1)) {
t = table.entry_for(catch_pco, -1, 0);
}
#ifdef COMPILER1
if (t == NULL && nm->is_compiled_by_c1()) {
assert(nm->unwind_handler_begin() != NULL, "");
return nm->unwind_handler_begin();
}
#endif
if (t == NULL) {
ttyLocker ttyl;
tty->print_cr("MISSING EXCEPTION HANDLER for pc " INTPTR_FORMAT " and handler bci %d", ret_pc, handler_bci);
tty->print_cr(" Exception:");
exception->print();
tty->cr();
tty->print_cr(" Compiled exception table :");
table.print();
nm->print_code();
guarantee(false, "missing exception handler");
return NULL;
}
return nm->code_begin() + t->pco();
}
JRT_ENTRY(void, SharedRuntime::throw_AbstractMethodError(JavaThread* thread))
throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_AbstractMethodError());
JRT_END
JRT_ENTRY(void, SharedRuntime::throw_IncompatibleClassChangeError(JavaThread* thread))
throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_IncompatibleClassChangeError(), "vtable stub");
JRT_END
JRT_ENTRY(void, SharedRuntime::throw_ArithmeticException(JavaThread* thread))
throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArithmeticException(), "/ by zero");
JRT_END
JRT_ENTRY(void, SharedRuntime::throw_NullPointerException(JavaThread* thread))
throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_NullPointerException());
JRT_END
JRT_ENTRY(void, SharedRuntime::throw_NullPointerException_at_call(JavaThread* thread))
throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_NullPointerException());
JRT_END
JRT_ENTRY(void, SharedRuntime::throw_StackOverflowError(JavaThread* thread))
Klass* k = SystemDictionary::StackOverflowError_klass();
oop exception_oop = InstanceKlass::cast(k)->allocate_instance(CHECK);
Handle exception (thread, exception_oop);
if (StackTraceInThrowable) {
java_lang_Throwable::fill_in_stack_trace(exception);
}
Atomic::inc(&Exceptions::_stack_overflow_errors);
throw_and_post_jvmti_exception(thread, exception);
JRT_END
address SharedRuntime::continuation_for_implicit_exception(JavaThread* thread,
address pc,
SharedRuntime::ImplicitExceptionKind exception_kind)
{
address target_pc = NULL;
if (Interpreter::contains(pc)) {
#ifdef CC_INTERP
ShouldNotReachHere();
#else
switch (exception_kind) {
case IMPLICIT_NULL: return Interpreter::throw_NullPointerException_entry();
case IMPLICIT_DIVIDE_BY_ZERO: return Interpreter::throw_ArithmeticException_entry();
case STACK_OVERFLOW: return Interpreter::throw_StackOverflowError_entry();
default: ShouldNotReachHere();
}
#endif // !CC_INTERP
} else {
switch (exception_kind) {
case STACK_OVERFLOW: {
assert(thread->deopt_mark() == NULL, "no stack overflow from deopt blob/uncommon trap");
Events::log_exception(thread, "StackOverflowError at " INTPTR_FORMAT, pc);
return StubRoutines::throw_StackOverflowError_entry();
}
case IMPLICIT_NULL: {
if (VtableStubs::contains(pc)) {
VtableStub* vt_stub = VtableStubs::stub_containing(pc);
if (vt_stub == NULL) return NULL;
if (vt_stub->is_abstract_method_error(pc)) {
assert(!vt_stub->is_vtable_stub(), "should never see AbstractMethodErrors from vtable-type VtableStubs");
Events::log_exception(thread, "AbstractMethodError at " INTPTR_FORMAT, pc);
return StubRoutines::throw_AbstractMethodError_entry();
} else {
Events::log_exception(thread, "NullPointerException at vtable entry " INTPTR_FORMAT, pc);
return StubRoutines::throw_NullPointerException_at_call_entry();
}
} else {
CodeBlob* cb = CodeCache::find_blob(pc);
if (cb == NULL) return NULL;
if (!cb->is_nmethod()) {
bool is_in_blob = cb->is_adapter_blob() || cb->is_method_handles_adapter_blob();
if (!is_in_blob) {
cb->print();
fatal(err_msg("exception happened outside interpreter, nmethods and vtable stubs at pc " INTPTR_FORMAT, pc));
}
Events::log_exception(thread, "NullPointerException in code blob at " INTPTR_FORMAT, pc);
return StubRoutines::throw_NullPointerException_at_call_entry();
}
nmethod* nm = (nmethod*)cb;
if (nm->inlinecache_check_contains(pc)) {
Events::log_exception(thread, "NullPointerException in IC check " INTPTR_FORMAT, pc);
return StubRoutines::throw_NullPointerException_at_call_entry();
}
if (nm->method()->is_method_handle_intrinsic()) {
Events::log_exception(thread, "NullPointerException in MH adapter " INTPTR_FORMAT, pc);
return StubRoutines::throw_NullPointerException_at_call_entry();
}
#ifndef PRODUCT
_implicit_null_throws++;
#endif
target_pc = nm->continuation_for_implicit_exception(pc);
}
break; // fall through
}
case IMPLICIT_DIVIDE_BY_ZERO: {
nmethod* nm = CodeCache::find_nmethod(pc);
guarantee(nm != NULL, "must have containing nmethod for implicit division-by-zero exceptions");
#ifndef PRODUCT
_implicit_div0_throws++;
#endif
target_pc = nm->continuation_for_implicit_exception(pc);
break; // fall through
}
default: ShouldNotReachHere();
}
assert(exception_kind == IMPLICIT_NULL || exception_kind == IMPLICIT_DIVIDE_BY_ZERO, "wrong implicit exception kind");
NOT_PRODUCT(Exceptions::debug_check_abort("java.lang.NullPointerException"));
if (exception_kind == IMPLICIT_NULL) {
Events::log_exception(thread, "Implicit null exception at " INTPTR_FORMAT " to " INTPTR_FORMAT, pc, target_pc);
} else {
Events::log_exception(thread, "Implicit division by zero exception at " INTPTR_FORMAT " to " INTPTR_FORMAT, pc, target_pc);
}
return target_pc;
}
ShouldNotReachHere();
return NULL;
}
JNI_ENTRY(void*, throw_unsatisfied_link_error(JNIEnv* env, ...))
{
THROW_(vmSymbols::java_lang_UnsatisfiedLinkError(), (void*)badJNIHandle);
}
JNI_END
address SharedRuntime::native_method_throw_unsatisfied_link_error_entry() {
return CAST_FROM_FN_PTR(address, &throw_unsatisfied_link_error);
}
#ifndef PRODUCT
JRT_ENTRY(intptr_t, SharedRuntime::trace_bytecode(JavaThread* thread, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2))
const frame f = thread->last_frame();
assert(f.is_interpreted_frame(), "must be an interpreted frame");
#ifndef PRODUCT
methodHandle mh(THREAD, f.interpreter_frame_method());
BytecodeTracer::trace(mh, f.interpreter_frame_bcp(), tos, tos2);
#endif // !PRODUCT
return preserve_this_value;
JRT_END
#endif // !PRODUCT
JRT_ENTRY(void, SharedRuntime::yield_all(JavaThread* thread, int attempts))
os::yield_all(attempts);
JRT_END
JRT_ENTRY_NO_ASYNC(void, SharedRuntime::register_finalizer(JavaThread* thread, oopDesc* obj))
assert(obj->is_oop(), "must be a valid oop");
assert(obj->klass()->has_finalizer(), "shouldn't be here otherwise");
InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
JRT_END
jlong SharedRuntime::get_java_tid(Thread* thread) {
if (thread != NULL) {
if (thread->is_Java_thread()) {
oop obj = ((JavaThread*)thread)->threadObj();
return (obj == NULL) ? 0 : java_lang_Thread::thread_id(obj);
}
}
return 0;
}
int SharedRuntime::dtrace_object_alloc(oopDesc* o, int size) {
return dtrace_object_alloc_base(Thread::current(), o, size);
}
int SharedRuntime::dtrace_object_alloc_base(Thread* thread, oopDesc* o, int size) {
assert(DTraceAllocProbes, "wrong call");
Klass* klass = o->klass();
Symbol* name = klass->name();
#ifndef USDT2
HS_DTRACE_PROBE4(hotspot, object__alloc, get_java_tid(thread),
name->bytes(), name->utf8_length(), size * HeapWordSize);
#else /* USDT2 */
HOTSPOT_OBJECT_ALLOC(
get_java_tid(thread),
(char *) name->bytes(), name->utf8_length(), size * HeapWordSize);
#endif /* USDT2 */
return 0;
}
JRT_LEAF(int, SharedRuntime::dtrace_method_entry(
JavaThread* thread, Method* method))
assert(DTraceMethodProbes, "wrong call");
Symbol* kname = method->klass_name();
Symbol* name = method->name();
Symbol* sig = method->signature();
#ifndef USDT2
HS_DTRACE_PROBE7(hotspot, method__entry, get_java_tid(thread),
kname->bytes(), kname->utf8_length(),
name->bytes(), name->utf8_length(),
sig->bytes(), sig->utf8_length());
#else /* USDT2 */
HOTSPOT_METHOD_ENTRY(
get_java_tid(thread),
(char *) kname->bytes(), kname->utf8_length(),
(char *) name->bytes(), name->utf8_length(),
(char *) sig->bytes(), sig->utf8_length());
#endif /* USDT2 */
return 0;
JRT_END
JRT_LEAF(int, SharedRuntime::dtrace_method_exit(
JavaThread* thread, Method* method))
assert(DTraceMethodProbes, "wrong call");
Symbol* kname = method->klass_name();
Symbol* name = method->name();
Symbol* sig = method->signature();
#ifndef USDT2
HS_DTRACE_PROBE7(hotspot, method__return, get_java_tid(thread),
kname->bytes(), kname->utf8_length(),
name->bytes(), name->utf8_length(),
sig->bytes(), sig->utf8_length());
#else /* USDT2 */
HOTSPOT_METHOD_RETURN(
get_java_tid(thread),
(char *) kname->bytes(), kname->utf8_length(),
(char *) name->bytes(), name->utf8_length(),
(char *) sig->bytes(), sig->utf8_length());
#endif /* USDT2 */
return 0;
JRT_END
Handle SharedRuntime::find_callee_info(JavaThread* thread, Bytecodes::Code& bc, CallInfo& callinfo, TRAPS) {
ResourceMark rm(THREAD);
vframeStream vfst(thread, true); // Do not skip and javaCalls
return find_callee_info_helper(thread, vfst, bc, callinfo, THREAD);
}
Handle SharedRuntime::find_callee_info_helper(JavaThread* thread,
vframeStream& vfst,
Bytecodes::Code& bc,
CallInfo& callinfo, TRAPS) {
Handle receiver;
Handle nullHandle; //create a handy null handle for exception returns
assert(!vfst.at_end(), "Java frame must exist");
methodHandle caller(THREAD, vfst.method());
int bci = vfst.bci();
Bytecode_invoke bytecode(caller, bci);
bc = bytecode.invoke_code();
int bytecode_index = bytecode.index();
if (bc != Bytecodes::_invokestatic &&
bc != Bytecodes::_invokedynamic &&
bc != Bytecodes::_invokehandle) {
RegisterMap reg_map2(thread);
frame stubFrame = thread->last_frame();
frame callerFrame = stubFrame.sender(®_map2);
methodHandle callee = bytecode.static_target(CHECK_(nullHandle));
if (callee.is_null()) {
THROW_(vmSymbols::java_lang_NoSuchMethodException(), nullHandle);
}
receiver = Handle(THREAD, callerFrame.retrieve_receiver(®_map2));
if (receiver.is_null()) {
THROW_(vmSymbols::java_lang_NullPointerException(), nullHandle);
}
}
constantPoolHandle constants(THREAD, caller->constants());
assert(receiver.is_null() || receiver->is_oop(), "wrong receiver");
LinkResolver::resolve_invoke(callinfo, receiver, constants, bytecode_index, bc, CHECK_(nullHandle));
#ifdef ASSERT
if (bc != Bytecodes::_invokestatic && bc != Bytecodes::_invokedynamic && bc != Bytecodes::_invokehandle) {
assert(receiver.not_null(), "should have thrown exception");
KlassHandle receiver_klass(THREAD, receiver->klass());
Klass* rk = constants->klass_ref_at(bytecode_index, CHECK_(nullHandle));
KlassHandle static_receiver_klass(THREAD, rk);
methodHandle callee = callinfo.selected_method();
assert(receiver_klass->is_subtype_of(static_receiver_klass()) ||
callee->is_method_handle_intrinsic() ||
callee->is_compiled_lambda_form(),
"actual receiver must be subclass of static receiver klass");
if (receiver_klass->oop_is_instance()) {
if (InstanceKlass::cast(receiver_klass())->is_not_initialized()) {
tty->print_cr("ERROR: Klass not yet initialized!!");
receiver_klass()->print();
}
assert(!InstanceKlass::cast(receiver_klass())->is_not_initialized(), "receiver_klass must be initialized");
}
}
#endif
return receiver;
}
methodHandle SharedRuntime::find_callee_method(JavaThread* thread, TRAPS) {
ResourceMark rm(THREAD);
vframeStream vfst(thread, true); // Do not skip any javaCalls
methodHandle callee_method;
if (vfst.at_end()) {
RegisterMap reg_map(thread, false);
frame fr = thread->last_frame();
assert(fr.is_runtime_frame(), "must be a runtimeStub");
fr = fr.sender(®_map);
assert(fr.is_entry_frame(), "must be");
callee_method = methodHandle(THREAD, fr.entry_frame_call_wrapper()->callee_method());
assert(fr.entry_frame_call_wrapper()->receiver() == NULL || !callee_method->is_static(), "non-null receiver for static call??");
} else {
Bytecodes::Code bc;
CallInfo callinfo;
find_callee_info_helper(thread, vfst, bc, callinfo, CHECK_(methodHandle()));
callee_method = callinfo.selected_method();
}
assert(callee_method()->is_method(), "must be");
return callee_method;
}
methodHandle SharedRuntime::resolve_helper(JavaThread *thread,
bool is_virtual,
bool is_optimized, TRAPS) {
methodHandle callee_method;
callee_method = resolve_sub_helper(thread, is_virtual, is_optimized, THREAD);
if (JvmtiExport::can_hotswap_or_post_breakpoint()) {
int retry_count = 0;
while (!HAS_PENDING_EXCEPTION && callee_method->is_old() &&
callee_method->method_holder() != SystemDictionary::Object_klass()) {
guarantee((retry_count++ < 100),
"Could not resolve to latest version of redefined method");
callee_method = resolve_sub_helper(thread, is_virtual, is_optimized, THREAD);
}
}
return callee_method;
}
methodHandle SharedRuntime::resolve_sub_helper(JavaThread *thread,
bool is_virtual,
bool is_optimized, TRAPS) {
ResourceMark rm(thread);
RegisterMap cbl_map(thread, false);
frame caller_frame = thread->last_frame().sender(&cbl_map);
CodeBlob* caller_cb = caller_frame.cb();
guarantee(caller_cb != NULL && caller_cb->is_nmethod(), "must be called from nmethod");
nmethod* caller_nm = caller_cb->as_nmethod_or_null();
nmethodLocker caller_lock(caller_nm);
CallInfo call_info;
Bytecodes::Code invoke_code = Bytecodes::_illegal;
Handle receiver = find_callee_info(thread, invoke_code,
call_info, CHECK_(methodHandle()));
methodHandle callee_method = call_info.selected_method();
assert((!is_virtual && invoke_code == Bytecodes::_invokestatic ) ||
(!is_virtual && invoke_code == Bytecodes::_invokehandle ) ||
(!is_virtual && invoke_code == Bytecodes::_invokedynamic) ||
( is_virtual && invoke_code != Bytecodes::_invokestatic ), "inconsistent bytecode");
assert(caller_nm->is_alive(), "It should be alive");
#ifndef PRODUCT
int *addr = (is_optimized) ? (&_resolve_opt_virtual_ctr) :
(is_virtual) ? (&_resolve_virtual_ctr) :
(&_resolve_static_ctr);
Atomic::inc(addr);
if (TraceCallFixup) {
ResourceMark rm(thread);
tty->print("resolving %s%s (%s) call to",
(is_optimized) ? "optimized " : "", (is_virtual) ? "virtual" : "static",
Bytecodes::name(invoke_code));
callee_method->print_short_name(tty);
tty->print_cr(" at pc: " INTPTR_FORMAT " to code: " INTPTR_FORMAT, caller_frame.pc(), callee_method->code());
}
#endif
if (invoke_code == Bytecodes::_invokestatic &&
!callee_method->method_holder()->is_initialized()) {
assert(callee_method->method_holder()->is_linked(), "must be");
return callee_method;
}
StaticCallInfo static_call_info;
CompiledICInfo virtual_call_info;
nmethod* callee_nm = callee_method->code();
if (callee_nm != NULL && !callee_nm->is_in_use()) {
callee_nm = NULL;
}
nmethodLocker nl_callee(callee_nm);
#ifdef ASSERT
address dest_entry_point = callee_nm == NULL ? 0 : callee_nm->entry_point(); // used below
#endif
if (is_virtual) {
assert(receiver.not_null() || invoke_code == Bytecodes::_invokehandle, "sanity check");
bool static_bound = call_info.resolved_method()->can_be_statically_bound();
KlassHandle h_klass(THREAD, invoke_code == Bytecodes::_invokehandle ? NULL : receiver->klass());
CompiledIC::compute_monomorphic_entry(callee_method, h_klass,
is_optimized, static_bound, virtual_call_info,
CHECK_(methodHandle()));
} else {
CompiledStaticCall::compute_entry(callee_method, static_call_info);
}
{
MutexLocker ml_patch(CompiledIC_lock);
if (!callee_method->is_old() &&
(callee_nm == NULL || callee_nm->is_in_use() && (callee_method->code() == callee_nm))) {
#ifdef ASSERT
if (dest_entry_point != 0) {
CodeBlob* cb = CodeCache::find_blob(dest_entry_point);
assert((cb != NULL) && cb->is_nmethod() && (((nmethod*)cb) == callee_nm),
"should not call unloaded nmethod");
}
#endif
if (is_virtual) {
nmethod* nm = callee_nm;
if (nm == NULL) CodeCache::find_blob(caller_frame.pc());
CompiledIC* inline_cache = CompiledIC_before(caller_nm, caller_frame.pc());
if (inline_cache->is_clean()) {
inline_cache->set_to_monomorphic(virtual_call_info);
}
} else {
CompiledStaticCall* ssc = compiledStaticCall_before(caller_frame.pc());
if (ssc->is_clean()) ssc->set(static_call_info);
}
}
} // unlock CompiledIC_lock
return callee_method;
}
JRT_BLOCK_ENTRY(address, SharedRuntime::handle_wrong_method_ic_miss(JavaThread* thread))
#ifdef ASSERT
RegisterMap reg_map(thread, false);
frame stub_frame = thread->last_frame();
assert(stub_frame.is_runtime_frame(), "sanity check");
frame caller_frame = stub_frame.sender(®_map);
assert(!caller_frame.is_interpreted_frame() && !caller_frame.is_entry_frame(), "unexpected frame");
#endif /* ASSERT */
methodHandle callee_method;
JRT_BLOCK
callee_method = SharedRuntime::handle_ic_miss_helper(thread, CHECK_NULL);
thread->set_vm_result_2(callee_method());
JRT_BLOCK_END
assert(callee_method->verified_code_entry() != NULL, " Jump to zero!");
return callee_method->verified_code_entry();
JRT_END
JRT_BLOCK_ENTRY(address, SharedRuntime::handle_wrong_method(JavaThread* thread))
RegisterMap reg_map(thread, false);
frame stub_frame = thread->last_frame();
assert(stub_frame.is_runtime_frame(), "sanity check");
frame caller_frame = stub_frame.sender(®_map);
if (caller_frame.is_interpreted_frame() ||
caller_frame.is_entry_frame()) {
Method* callee = thread->callee_target();
guarantee(callee != NULL && callee->is_method(), "bad handshake");
thread->set_vm_result_2(callee);
thread->set_callee_target(NULL);
return callee->get_c2i_entry();
}
methodHandle callee_method;
JRT_BLOCK
callee_method = SharedRuntime::reresolve_call_site(thread, CHECK_NULL);
thread->set_vm_result_2(callee_method());
JRT_BLOCK_END
assert(callee_method->verified_code_entry() != NULL, " Jump to zero!");
return callee_method->verified_code_entry();
JRT_END
JRT_BLOCK_ENTRY(address, SharedRuntime::handle_wrong_method_abstract(JavaThread* thread))
return StubRoutines::throw_AbstractMethodError_entry();
JRT_END
JRT_BLOCK_ENTRY(address, SharedRuntime::resolve_static_call_C(JavaThread *thread ))
methodHandle callee_method;
JRT_BLOCK
callee_method = SharedRuntime::resolve_helper(thread, false, false, CHECK_NULL);
thread->set_vm_result_2(callee_method());
JRT_BLOCK_END
assert(callee_method->verified_code_entry() != NULL, " Jump to zero!");
return callee_method->verified_code_entry();
JRT_END
JRT_BLOCK_ENTRY(address, SharedRuntime::resolve_virtual_call_C(JavaThread *thread ))
methodHandle callee_method;
JRT_BLOCK
callee_method = SharedRuntime::resolve_helper(thread, true, false, CHECK_NULL);
thread->set_vm_result_2(callee_method());
JRT_BLOCK_END
assert(callee_method->verified_code_entry() != NULL, " Jump to zero!");
return callee_method->verified_code_entry();
JRT_END
JRT_BLOCK_ENTRY(address, SharedRuntime::resolve_opt_virtual_call_C(JavaThread *thread))
methodHandle callee_method;
JRT_BLOCK
callee_method = SharedRuntime::resolve_helper(thread, true, true, CHECK_NULL);
thread->set_vm_result_2(callee_method());
JRT_BLOCK_END
assert(callee_method->verified_code_entry() != NULL, " Jump to zero!");
return callee_method->verified_code_entry();
JRT_END
methodHandle SharedRuntime::handle_ic_miss_helper(JavaThread *thread, TRAPS) {
ResourceMark rm(thread);
CallInfo call_info;
Bytecodes::Code bc;
Handle receiver = find_callee_info(thread, bc, call_info,
CHECK_(methodHandle()));
if (call_info.resolved_method()->can_be_statically_bound()) {
methodHandle callee_method = SharedRuntime::reresolve_call_site(thread, CHECK_(methodHandle()));
if (TraceCallFixup) {
RegisterMap reg_map(thread, false);
frame caller_frame = thread->last_frame().sender(®_map);
ResourceMark rm(thread);
tty->print("converting IC miss to reresolve (%s) call to", Bytecodes::name(bc));
callee_method->print_short_name(tty);
tty->print_cr(" from pc: " INTPTR_FORMAT, caller_frame.pc());
tty->print_cr(" code: " INTPTR_FORMAT, callee_method->code());
}
return callee_method;
}
methodHandle callee_method = call_info.selected_method();
bool should_be_mono = false;
#ifndef PRODUCT
Atomic::inc(&_ic_miss_ctr);
if (TraceCallFixup) {
ResourceMark rm(thread);
tty->print("IC miss (%s) call to", Bytecodes::name(bc));
callee_method->print_short_name(tty);
tty->print_cr(" code: " INTPTR_FORMAT, callee_method->code());
}
if (ICMissHistogram) {
MutexLocker m(VMStatistic_lock);
RegisterMap reg_map(thread, false);
frame f = thread->last_frame().real_sender(®_map);// skip runtime stub
trace_ic_miss(f.pc());
}
#endif
JvmtiDynamicCodeEventCollector event_collector;
{ MutexLocker ml_patch (CompiledIC_lock);
RegisterMap reg_map(thread, false);
frame caller_frame = thread->last_frame().sender(®_map);
CodeBlob* cb = caller_frame.cb();
if (cb->is_nmethod()) {
CompiledIC* inline_cache = CompiledIC_before(((nmethod*)cb), caller_frame.pc());
bool should_be_mono = false;
if (inline_cache->is_optimized()) {
if (TraceCallFixup) {
ResourceMark rm(thread);
tty->print("OPTIMIZED IC miss (%s) call to", Bytecodes::name(bc));
callee_method->print_short_name(tty);
tty->print_cr(" code: " INTPTR_FORMAT, callee_method->code());
}
should_be_mono = true;
} else if (inline_cache->is_icholder_call()) {
CompiledICHolder* ic_oop = inline_cache->cached_icholder();
if ( ic_oop != NULL) {
if (receiver()->klass() == ic_oop->holder_klass()) {
if (TraceCallFixup) {
ResourceMark rm(thread);
tty->print("FALSE IC miss (%s) converting to compiled call to", Bytecodes::name(bc));
callee_method->print_short_name(tty);
tty->print_cr(" code: " INTPTR_FORMAT, callee_method->code());
}
should_be_mono = true;
}
}
}
if (should_be_mono) {
CompiledICInfo info;
KlassHandle receiver_klass(THREAD, receiver()->klass());
inline_cache->compute_monomorphic_entry(callee_method,
receiver_klass,
inline_cache->is_optimized(),
false,
info, CHECK_(methodHandle()));
inline_cache->set_to_monomorphic(info);
} else if (!inline_cache->is_megamorphic() && !inline_cache->is_clean()) {
bool successful = inline_cache->set_to_megamorphic(&call_info, bc, CHECK_(methodHandle()));
if (!successful) {
inline_cache->set_to_clean();
}
} else {
}
}
} // Release CompiledIC_lock
return callee_method;
}
methodHandle SharedRuntime::reresolve_call_site(JavaThread *thread, TRAPS) {
ResourceMark rm(thread);
RegisterMap reg_map(thread, false);
frame stub_frame = thread->last_frame();
assert(stub_frame.is_runtime_frame(), "must be a runtimeStub");
frame caller = stub_frame.sender(®_map);
if (caller.is_compiled_frame() && !caller.is_deoptimized_frame()) {
address pc = caller.pc();
address call_addr = NULL;
{
MutexLockerEx ml_patch(Patching_lock, Mutex::_no_safepoint_check_flag);
if (NativeCall::is_call_before(pc)) {
NativeCall *ncall = nativeCall_before(pc);
call_addr = ncall->instruction_address();
}
}
bool is_static_call = false;
nmethod* caller_nm = CodeCache::find_nmethod(pc);
nmethodLocker nmlock(caller_nm);
if (call_addr != NULL) {
RelocIterator iter(caller_nm, call_addr, call_addr+1);
int ret = iter.next(); // Get item
if (ret) {
assert(iter.addr() == call_addr, "must find call");
if (iter.type() == relocInfo::static_call_type) {
is_static_call = true;
} else {
assert(iter.type() == relocInfo::virtual_call_type ||
iter.type() == relocInfo::opt_virtual_call_type
, "unexpected relocInfo. type");
}
} else {
assert(!UseInlineCaches, "relocation info. must exist for this address");
}
MutexLocker ml(CompiledIC_lock);
if (is_static_call) {
CompiledStaticCall* ssc= compiledStaticCall_at(call_addr);
ssc->set_to_clean();
} else {
CompiledIC* inline_cache = CompiledIC_at(caller_nm, call_addr);
inline_cache->set_to_clean();
}
}
}
methodHandle callee_method = find_callee_method(thread, CHECK_(methodHandle()));
#ifndef PRODUCT
Atomic::inc(&_wrong_method_ctr);
if (TraceCallFixup) {
ResourceMark rm(thread);
tty->print("handle_wrong_method reresolving call to");
callee_method->print_short_name(tty);
tty->print_cr(" code: " INTPTR_FORMAT, callee_method->code());
}
#endif
return callee_method;
}
#ifdef ASSERT
void SharedRuntime::check_member_name_argument_is_last_argument(methodHandle method,
const BasicType* sig_bt,
const VMRegPair* regs) {
ResourceMark rm;
const int total_args_passed = method->size_of_parameters();
const VMRegPair* regs_with_member_name = regs;
VMRegPair* regs_without_member_name = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed - 1);
const int member_arg_pos = total_args_passed - 1;
assert(member_arg_pos >= 0 && member_arg_pos < total_args_passed, "oob");
assert(sig_bt[member_arg_pos] == T_OBJECT, "dispatch argument must be an object");
const bool is_outgoing = method->is_method_handle_intrinsic();
int comp_args_on_stack = java_calling_convention(sig_bt, regs_without_member_name, total_args_passed - 1, is_outgoing);
for (int i = 0; i < member_arg_pos; i++) {
VMReg a = regs_with_member_name[i].first();
VMReg b = regs_without_member_name[i].first();
assert(a->value() == b->value(), err_msg_res("register allocation mismatch: a=%d, b=%d", a->value(), b->value()));
}
assert(regs_with_member_name[member_arg_pos].first()->is_valid(), "bad member arg");
}
#endif
IRT_LEAF(void, SharedRuntime::fixup_callers_callsite(Method* method, address caller_pc))
Method* moop(method);
address entry_point = moop->from_compiled_entry();
CodeBlob* cb = CodeCache::find_blob(caller_pc);
if (cb == NULL || !cb->is_nmethod() || entry_point == moop->get_c2i_entry()) {
return;
}
nmethod* nm = cb->as_nmethod_or_null();
assert(nm, "must be");
address return_pc = caller_pc + frame::pc_return_offset;
if (moop->code() == NULL) return;
if (nm->is_in_use()) {
MutexLockerEx ml_patch(Patching_lock, Mutex::_no_safepoint_check_flag);
if (NativeCall::is_call_before(return_pc)) {
NativeCall *call = nativeCall_before(return_pc);
RelocIterator iter(nm, call->instruction_address(), call->next_instruction_address());
iter.next();
assert(iter.has_current(), "must have a reloc at java call site");
relocInfo::relocType typ = iter.reloc()->type();
if ( typ != relocInfo::static_call_type &&
typ != relocInfo::opt_virtual_call_type &&
typ != relocInfo::static_stub_type) {
return;
}
address destination = call->destination();
if (destination != entry_point) {
CodeBlob* callee = CodeCache::find_blob(destination);
if (callee != NULL && (callee == cb || callee->is_adapter_blob())) {
if (TraceCallFixup) {
tty->print("fixup callsite at " INTPTR_FORMAT " to compiled code for", caller_pc);
moop->print_short_name(tty);
tty->print_cr(" to " INTPTR_FORMAT, entry_point);
}
call->set_destination_mt_safe(entry_point);
} else {
if (TraceCallFixup) {
tty->print("failed to fixup callsite at " INTPTR_FORMAT " to compiled code for", caller_pc);
moop->print_short_name(tty);
tty->print_cr(" to " INTPTR_FORMAT, entry_point);
}
}
} else {
if (TraceCallFixup) {
tty->print("already patched callsite at " INTPTR_FORMAT " to compiled code for", caller_pc);
moop->print_short_name(tty);
tty->print_cr(" to " INTPTR_FORMAT, entry_point);
}
}
}
}
IRT_END
JRT_ENTRY(void, SharedRuntime::slow_arraycopy_C(oopDesc* src, jint src_pos,
oopDesc* dest, jint dest_pos,
jint length,
JavaThread* thread)) {
#ifndef PRODUCT
_slow_array_copy_ctr++;
#endif
if (src == NULL || dest == NULL) {
THROW(vmSymbols::java_lang_NullPointerException());
}
src->klass()->copy_array((arrayOopDesc*)src, src_pos,
(arrayOopDesc*)dest, dest_pos,
length, thread);
}
JRT_END
char* SharedRuntime::generate_class_cast_message(
JavaThread* thread, const char* objName) {
vframeStream vfst(thread, true);
assert(!vfst.at_end(), "Java frame must exist");
Bytecode_checkcast cc(vfst.method(), vfst.method()->bcp_from(vfst.bci()));
Klass* targetKlass = vfst.method()->constants()->klass_at(
cc.index(), thread);
return generate_class_cast_message(objName, targetKlass->external_name());
}
char* SharedRuntime::generate_class_cast_message(
const char* objName, const char* targetKlassName, const char* desc) {
size_t msglen = strlen(objName) + strlen(desc) + strlen(targetKlassName) + 1;
char* message = NEW_RESOURCE_ARRAY(char, msglen);
if (NULL == message) {
message = const_cast<char*>(objName);
} else {
jio_snprintf(message, msglen, "%s%s%s", objName, desc, targetKlassName);
}
return message;
}
JRT_LEAF(void, SharedRuntime::reguard_yellow_pages())
(void) JavaThread::current()->reguard_stack();
JRT_END
#ifndef PRODUCT
int SharedRuntime::_monitor_enter_ctr=0;
#endif
JRT_ENTRY_NO_ASYNC(void, SharedRuntime::complete_monitor_locking_C(oopDesc* _obj, BasicLock* lock, JavaThread* thread))
oop obj(_obj);
#ifndef PRODUCT
_monitor_enter_ctr++; // monitor enter slow
#endif
if (PrintBiasedLockingStatistics) {
Atomic::inc(BiasedLocking::slow_path_entry_count_addr());
}
Handle h_obj(THREAD, obj);
if (UseBiasedLocking) {
ObjectSynchronizer::fast_enter(h_obj, lock, true, CHECK);
} else {
ObjectSynchronizer::slow_enter(h_obj, lock, CHECK);
}
assert(!HAS_PENDING_EXCEPTION, "Should have no exception here");
JRT_END
#ifndef PRODUCT
int SharedRuntime::_monitor_exit_ctr=0;
#endif
JRT_LEAF(void, SharedRuntime::complete_monitor_unlocking_C(oopDesc* _obj, BasicLock* lock))
oop obj(_obj);
#ifndef PRODUCT
_monitor_exit_ctr++; // monitor exit slow
#endif
Thread* THREAD = JavaThread::current();
assert(!HAS_PENDING_EXCEPTION, "Do we need code below anymore?");
#undef MIGHT_HAVE_PENDING
#ifdef MIGHT_HAVE_PENDING
oop pending_excep = NULL;
const char* pending_file;
int pending_line;
if (HAS_PENDING_EXCEPTION) {
pending_excep = PENDING_EXCEPTION;
pending_file = THREAD->exception_file();
pending_line = THREAD->exception_line();
CLEAR_PENDING_EXCEPTION;
}
#endif /* MIGHT_HAVE_PENDING */
{
EXCEPTION_MARK;
ObjectSynchronizer::slow_exit(obj, lock, THREAD);
}
#ifdef MIGHT_HAVE_PENDING
if (pending_excep != NULL) {
THREAD->set_pending_exception(pending_excep, pending_file, pending_line);
}
#endif /* MIGHT_HAVE_PENDING */
JRT_END
#ifndef PRODUCT
void SharedRuntime::print_statistics() {
ttyLocker ttyl;
if (xtty != NULL) xtty->head("statistics type='SharedRuntime'");
if (_monitor_enter_ctr ) tty->print_cr("%5d monitor enter slow", _monitor_enter_ctr);
if (_monitor_exit_ctr ) tty->print_cr("%5d monitor exit slow", _monitor_exit_ctr);
if (_throw_null_ctr) tty->print_cr("%5d implicit null throw", _throw_null_ctr);
SharedRuntime::print_ic_miss_histogram();
if (CountRemovableExceptions) {
if (_nof_removable_exceptions > 0) {
Unimplemented(); // this counter is not yet incremented
tty->print_cr("Removable exceptions: %d", _nof_removable_exceptions);
}
}
if( _new_instance_ctr ) tty->print_cr("%5d new instance requires GC", _new_instance_ctr);
if( _new_array_ctr ) tty->print_cr("%5d new array requires GC", _new_array_ctr);
if( _multi1_ctr ) tty->print_cr("%5d multianewarray 1 dim", _multi1_ctr);
if( _multi2_ctr ) tty->print_cr("%5d multianewarray 2 dim", _multi2_ctr);
if( _multi3_ctr ) tty->print_cr("%5d multianewarray 3 dim", _multi3_ctr);
if( _multi4_ctr ) tty->print_cr("%5d multianewarray 4 dim", _multi4_ctr);
if( _multi5_ctr ) tty->print_cr("%5d multianewarray 5 dim", _multi5_ctr);
tty->print_cr("%5d inline cache miss in compiled", _ic_miss_ctr );
tty->print_cr("%5d wrong method", _wrong_method_ctr );
tty->print_cr("%5d unresolved static call site", _resolve_static_ctr );
tty->print_cr("%5d unresolved virtual call site", _resolve_virtual_ctr );
tty->print_cr("%5d unresolved opt virtual call site", _resolve_opt_virtual_ctr );
if( _mon_enter_stub_ctr ) tty->print_cr("%5d monitor enter stub", _mon_enter_stub_ctr );
if( _mon_exit_stub_ctr ) tty->print_cr("%5d monitor exit stub", _mon_exit_stub_ctr );
if( _mon_enter_ctr ) tty->print_cr("%5d monitor enter slow", _mon_enter_ctr );
if( _mon_exit_ctr ) tty->print_cr("%5d monitor exit slow", _mon_exit_ctr );
if( _partial_subtype_ctr) tty->print_cr("%5d slow partial subtype", _partial_subtype_ctr );
if( _jbyte_array_copy_ctr ) tty->print_cr("%5d byte array copies", _jbyte_array_copy_ctr );
if( _jshort_array_copy_ctr ) tty->print_cr("%5d short array copies", _jshort_array_copy_ctr );
if( _jint_array_copy_ctr ) tty->print_cr("%5d int array copies", _jint_array_copy_ctr );
if( _jlong_array_copy_ctr ) tty->print_cr("%5d long array copies", _jlong_array_copy_ctr );
if( _oop_array_copy_ctr ) tty->print_cr("%5d oop array copies", _oop_array_copy_ctr );
if( _checkcast_array_copy_ctr ) tty->print_cr("%5d checkcast array copies", _checkcast_array_copy_ctr );
if( _unsafe_array_copy_ctr ) tty->print_cr("%5d unsafe array copies", _unsafe_array_copy_ctr );
if( _generic_array_copy_ctr ) tty->print_cr("%5d generic array copies", _generic_array_copy_ctr );
if( _slow_array_copy_ctr ) tty->print_cr("%5d slow array copies", _slow_array_copy_ctr );
if( _find_handler_ctr ) tty->print_cr("%5d find exception handler", _find_handler_ctr );
if( _rethrow_ctr ) tty->print_cr("%5d rethrow handler", _rethrow_ctr );
AdapterHandlerLibrary::print_statistics();
if (xtty != NULL) xtty->tail("statistics");
}
inline double percent(int x, int y) {
return 100.0 * x / MAX2(y, 1);
}
class MethodArityHistogram {
public:
enum { MAX_ARITY = 256 };
private:
static int _arity_histogram[MAX_ARITY]; // histogram of #args
static int _size_histogram[MAX_ARITY]; // histogram of arg size in words
static int _max_arity; // max. arity seen
static int _max_size; // max. arg size seen
static void add_method_to_histogram(nmethod* nm) {
Method* m = nm->method();
ArgumentCount args(m->signature());
int arity = args.size() + (m->is_static() ? 0 : 1);
int argsize = m->size_of_parameters();
arity = MIN2(arity, MAX_ARITY-1);
argsize = MIN2(argsize, MAX_ARITY-1);
int count = nm->method()->compiled_invocation_count();
_arity_histogram[arity] += count;
_size_histogram[argsize] += count;
_max_arity = MAX2(_max_arity, arity);
_max_size = MAX2(_max_size, argsize);
}
void print_histogram_helper(int n, int* histo, const char* name) {
const int N = MIN2(5, n);
tty->print_cr("\nHistogram of call arity (incl. rcvr, calls to compiled methods only):");
double sum = 0;
double weighted_sum = 0;
int i;
for (i = 0; i <= n; i++) { sum += histo[i]; weighted_sum += i*histo[i]; }
double rest = sum;
double percent = sum / 100;
for (i = 0; i <= N; i++) {
rest -= histo[i];
tty->print_cr("%4d: %7d (%5.1f%%)", i, histo[i], histo[i] / percent);
}
tty->print_cr("rest: %7d (%5.1f%%))", (int)rest, rest / percent);
tty->print_cr("(avg. %s = %3.1f, max = %d)", name, weighted_sum / sum, n);
}
void print_histogram() {
tty->print_cr("\nHistogram of call arity (incl. rcvr, calls to compiled methods only):");
print_histogram_helper(_max_arity, _arity_histogram, "arity");
tty->print_cr("\nSame for parameter size (in words):");
print_histogram_helper(_max_size, _size_histogram, "size");
tty->cr();
}
public:
MethodArityHistogram() {
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
_max_arity = _max_size = 0;
for (int i = 0; i < MAX_ARITY; i++) _arity_histogram[i] = _size_histogram [i] = 0;
CodeCache::nmethods_do(add_method_to_histogram);
print_histogram();
}
};
int MethodArityHistogram::_arity_histogram[MethodArityHistogram::MAX_ARITY];
int MethodArityHistogram::_size_histogram[MethodArityHistogram::MAX_ARITY];
int MethodArityHistogram::_max_arity;
int MethodArityHistogram::_max_size;
void SharedRuntime::print_call_statistics(int comp_total) {
tty->print_cr("Calls from compiled code:");
int total = _nof_normal_calls + _nof_interface_calls + _nof_static_calls;
int mono_c = _nof_normal_calls - _nof_optimized_calls - _nof_megamorphic_calls;
int mono_i = _nof_interface_calls - _nof_optimized_interface_calls - _nof_megamorphic_interface_calls;
tty->print_cr("\t%9d (%4.1f%%) total non-inlined ", total, percent(total, total));
tty->print_cr("\t%9d (%4.1f%%) virtual calls ", _nof_normal_calls, percent(_nof_normal_calls, total));
tty->print_cr("\t %9d (%3.0f%%) inlined ", _nof_inlined_calls, percent(_nof_inlined_calls, _nof_normal_calls));
tty->print_cr("\t %9d (%3.0f%%) optimized ", _nof_optimized_calls, percent(_nof_optimized_calls, _nof_normal_calls));
tty->print_cr("\t %9d (%3.0f%%) monomorphic ", mono_c, percent(mono_c, _nof_normal_calls));
tty->print_cr("\t %9d (%3.0f%%) megamorphic ", _nof_megamorphic_calls, percent(_nof_megamorphic_calls, _nof_normal_calls));
tty->print_cr("\t%9d (%4.1f%%) interface calls ", _nof_interface_calls, percent(_nof_interface_calls, total));
tty->print_cr("\t %9d (%3.0f%%) inlined ", _nof_inlined_interface_calls, percent(_nof_inlined_interface_calls, _nof_interface_calls));
tty->print_cr("\t %9d (%3.0f%%) optimized ", _nof_optimized_interface_calls, percent(_nof_optimized_interface_calls, _nof_interface_calls));
tty->print_cr("\t %9d (%3.0f%%) monomorphic ", mono_i, percent(mono_i, _nof_interface_calls));
tty->print_cr("\t %9d (%3.0f%%) megamorphic ", _nof_megamorphic_interface_calls, percent(_nof_megamorphic_interface_calls, _nof_interface_calls));
tty->print_cr("\t%9d (%4.1f%%) static/special calls", _nof_static_calls, percent(_nof_static_calls, total));
tty->print_cr("\t %9d (%3.0f%%) inlined ", _nof_inlined_static_calls, percent(_nof_inlined_static_calls, _nof_static_calls));
tty->cr();
tty->print_cr("Note 1: counter updates are not MT-safe.");
tty->print_cr("Note 2: %% in major categories are relative to total non-inlined calls;");
tty->print_cr(" %% in nested categories are relative to their category");
tty->print_cr(" (and thus add up to more than 100%% with inlining)");
tty->cr();
MethodArityHistogram h;
}
#endif
class AdapterFingerPrint : public CHeapObj<mtCode> {
private:
enum {
_basic_type_bits = 4,
_basic_type_mask = right_n_bits(_basic_type_bits),
_basic_types_per_int = BitsPerInt / _basic_type_bits,
_compact_int_count = 3
};
union {
int _compact[_compact_int_count];
int* _fingerprint;
} _value;
int _length; // A negative length indicates the fingerprint is in the compact form,
static int adapter_encoding(BasicType in) {
switch(in) {
case T_BOOLEAN:
case T_BYTE:
case T_SHORT:
case T_CHAR:
return T_INT;
case T_OBJECT:
case T_ARRAY:
#ifdef _LP64
return T_LONG;
#else
return T_INT;
#endif
case T_INT:
case T_LONG:
case T_FLOAT:
case T_DOUBLE:
case T_VOID:
return in;
default:
ShouldNotReachHere();
return T_CONFLICT;
}
}
public:
AdapterFingerPrint(int total_args_passed, BasicType* sig_bt) {
int* ptr;
int len = (total_args_passed + (_basic_types_per_int-1)) / _basic_types_per_int;
if (len <= _compact_int_count) {
assert(_compact_int_count == 3, "else change next line");
_value._compact[0] = _value._compact[1] = _value._compact[2] = 0;
_length = -len;
ptr = _value._compact;
} else {
_length = len;
_value._fingerprint = NEW_C_HEAP_ARRAY(int, _length, mtCode);
ptr = _value._fingerprint;
}
int sig_index = 0;
for (int index = 0; index < len; index++) {
int value = 0;
for (int byte = 0; byte < _basic_types_per_int; byte++) {
int bt = ((sig_index < total_args_passed)
? adapter_encoding(sig_bt[sig_index++])
: 0);
assert((bt & _basic_type_mask) == bt, "must fit in 4 bits");
value = (value << _basic_type_bits) | bt;
}
ptr[index] = value;
}
}
~AdapterFingerPrint() {
if (_length > 0) {
FREE_C_HEAP_ARRAY(int, _value._fingerprint, mtCode);
}
}
int value(int index) {
if (_length < 0) {
return _value._compact[index];
}
return _value._fingerprint[index];
}
int length() {
if (_length < 0) return -_length;
return _length;
}
bool is_compact() {
return _length <= 0;
}
unsigned int compute_hash() {
int hash = 0;
for (int i = 0; i < length(); i++) {
int v = value(i);
hash = (hash << 8) ^ v ^ (hash >> 5);
}
return (unsigned int)hash;
}
const char* as_string() {
stringStream st;
st.print("0x");
for (int i = 0; i < length(); i++) {
st.print("%08x", value(i));
}
return st.as_string();
}
bool equals(AdapterFingerPrint* other) {
if (other->_length != _length) {
return false;
}
if (_length < 0) {
assert(_compact_int_count == 3, "else change next line");
return _value._compact[0] == other->_value._compact[0] &&
_value._compact[1] == other->_value._compact[1] &&
_value._compact[2] == other->_value._compact[2];
} else {
for (int i = 0; i < _length; i++) {
if (_value._fingerprint[i] != other->_value._fingerprint[i]) {
return false;
}
}
}
return true;
}
};
class AdapterHandlerTable : public BasicHashtable<mtCode> {
friend class AdapterHandlerTableIterator;
private:
#ifndef PRODUCT
static int _lookups; // number of calls to lookup
static int _buckets; // number of buckets checked
static int _equals; // number of buckets checked with matching hash
static int _hits; // number of successful lookups
static int _compact; // number of equals calls with compact signature
#endif
AdapterHandlerEntry* bucket(int i) {
return (AdapterHandlerEntry*)BasicHashtable<mtCode>::bucket(i);
}
public:
AdapterHandlerTable()
: BasicHashtable<mtCode>(293, sizeof(AdapterHandlerEntry)) { }
AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry, address c2i_unverified_entry) {
AdapterHandlerEntry* entry = (AdapterHandlerEntry*)BasicHashtable<mtCode>::new_entry(fingerprint->compute_hash());
entry->init(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
return entry;
}
void add(AdapterHandlerEntry* entry) {
int index = hash_to_index(entry->hash());
add_entry(index, entry);
}
void free_entry(AdapterHandlerEntry* entry) {
entry->deallocate();
BasicHashtable<mtCode>::free_entry(entry);
}
AdapterHandlerEntry* lookup(int total_args_passed, BasicType* sig_bt) {
NOT_PRODUCT(_lookups++);
AdapterFingerPrint fp(total_args_passed, sig_bt);
unsigned int hash = fp.compute_hash();
int index = hash_to_index(hash);
for (AdapterHandlerEntry* e = bucket(index); e != NULL; e = e->next()) {
NOT_PRODUCT(_buckets++);
if (e->hash() == hash) {
NOT_PRODUCT(_equals++);
if (fp.equals(e->fingerprint())) {
#ifndef PRODUCT
if (fp.is_compact()) _compact++;
_hits++;
#endif
return e;
}
}
}
return NULL;
}
#ifndef PRODUCT
void print_statistics() {
ResourceMark rm;
int longest = 0;
int empty = 0;
int total = 0;
int nonempty = 0;
for (int index = 0; index < table_size(); index++) {
int count = 0;
for (AdapterHandlerEntry* e = bucket(index); e != NULL; e = e->next()) {
count++;
}
if (count != 0) nonempty++;
if (count == 0) empty++;
if (count > longest) longest = count;
total += count;
}
tty->print_cr("AdapterHandlerTable: empty %d longest %d total %d average %f",
empty, longest, total, total / (double)nonempty);
tty->print_cr("AdapterHandlerTable: lookups %d buckets %d equals %d hits %d compact %d",
_lookups, _buckets, _equals, _hits, _compact);
}
#endif
};
#ifndef PRODUCT
int AdapterHandlerTable::_lookups;
int AdapterHandlerTable::_buckets;
int AdapterHandlerTable::_equals;
int AdapterHandlerTable::_hits;
int AdapterHandlerTable::_compact;
#endif
class AdapterHandlerTableIterator : public StackObj {
private:
AdapterHandlerTable* _table;
int _index;
AdapterHandlerEntry* _current;
void scan() {
while (_index < _table->table_size()) {
AdapterHandlerEntry* a = _table->bucket(_index);
_index++;
if (a != NULL) {
_current = a;
return;
}
}
}
public:
AdapterHandlerTableIterator(AdapterHandlerTable* table): _table(table), _index(0), _current(NULL) {
scan();
}
bool has_next() {
return _current != NULL;
}
AdapterHandlerEntry* next() {
if (_current != NULL) {
AdapterHandlerEntry* result = _current;
_current = _current->next();
if (_current == NULL) scan();
return result;
} else {
return NULL;
}
}
};
AdapterHandlerTable* AdapterHandlerLibrary::_adapters = NULL;
AdapterHandlerEntry* AdapterHandlerLibrary::_abstract_method_handler = NULL;
const int AdapterHandlerLibrary_size = 16*K;
BufferBlob* AdapterHandlerLibrary::_buffer = NULL;
BufferBlob* AdapterHandlerLibrary::buffer_blob() {
if (_buffer == NULL) // Initialize lazily
_buffer = BufferBlob::create("adapters", AdapterHandlerLibrary_size);
return _buffer;
}
void AdapterHandlerLibrary::initialize() {
if (_adapters != NULL) return;
_adapters = new AdapterHandlerTable();
address wrong_method_abstract = SharedRuntime::get_handle_wrong_method_abstract_stub();
_abstract_method_handler = AdapterHandlerLibrary::new_entry(new AdapterFingerPrint(0, NULL),
StubRoutines::throw_AbstractMethodError_entry(),
wrong_method_abstract, wrong_method_abstract);
}
AdapterHandlerEntry* AdapterHandlerLibrary::new_entry(AdapterFingerPrint* fingerprint,
address i2c_entry,
address c2i_entry,
address c2i_unverified_entry) {
return _adapters->new_entry(fingerprint, i2c_entry, c2i_entry, c2i_unverified_entry);
}
AdapterHandlerEntry* AdapterHandlerLibrary::get_adapter(methodHandle method) {
address ic_miss = SharedRuntime::get_ic_miss_stub();
assert(ic_miss != NULL, "must have handler");
ResourceMark rm;
NOT_PRODUCT(int insts_size);
AdapterBlob* new_adapter = NULL;
AdapterHandlerEntry* entry = NULL;
AdapterFingerPrint* fingerprint = NULL;
{
MutexLocker mu(AdapterHandlerLibrary_lock);
initialize();
if (method->is_abstract()) {
return _abstract_method_handler;
}
int total_args_passed = method->size_of_parameters(); // All args on stack
BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_args_passed);
VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed);
int i = 0;
if (!method->is_static()) // Pass in receiver first
sig_bt[i++] = T_OBJECT;
for (SignatureStream ss(method->signature()); !ss.at_return_type(); ss.next()) {
sig_bt[i++] = ss.type(); // Collect remaining bits of signature
if (ss.type() == T_LONG || ss.type() == T_DOUBLE)
sig_bt[i++] = T_VOID; // Longs & doubles take 2 Java slots
}
assert(i == total_args_passed, "");
entry = _adapters->lookup(total_args_passed, sig_bt);
#ifdef ASSERT
AdapterHandlerEntry* shared_entry = NULL;
if (VerifyAdapterSharing && (entry != NULL)) {
shared_entry = entry;
entry = NULL;
}
#endif
if (entry != NULL) {
return entry;
}
int comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, false);
fingerprint = new AdapterFingerPrint(total_args_passed, sig_bt);
bool contains_all_checks = StubRoutines::code2() != NULL;
BufferBlob* buf = buffer_blob(); // the temporary code buffer in CodeCache
if (buf != NULL) {
CodeBuffer buffer(buf);
short buffer_locs[20];
buffer.insts()->initialize_shared_locs((relocInfo*)buffer_locs,
sizeof(buffer_locs)/sizeof(relocInfo));
MacroAssembler _masm(&buffer);
entry = SharedRuntime::generate_i2c2i_adapters(&_masm,
total_args_passed,
comp_args_on_stack,
sig_bt,
regs,
fingerprint);
#ifdef ASSERT
if (VerifyAdapterSharing) {
if (shared_entry != NULL) {
assert(shared_entry->compare_code(buf->code_begin(), buffer.insts_size()), "code must match");
_adapters->free_entry(entry);
return shared_entry;
} else {
entry->save_code(buf->code_begin(), buffer.insts_size());
}
}
#endif
new_adapter = AdapterBlob::create(&buffer);
NOT_PRODUCT(insts_size = buffer.insts_size());
}
if (new_adapter == NULL) {
MutexUnlocker mu(AdapterHandlerLibrary_lock);
CompileBroker::handle_full_code_cache();
return NULL; // Out of CodeCache space
}
entry->relocate(new_adapter->content_begin());
#ifndef PRODUCT
if (PrintAdapterHandlers || PrintStubCode) {
ttyLocker ttyl;
entry->print_adapter_on(tty);
tty->print_cr("i2c argument handler #%d for: %s %s (%d bytes generated)",
_adapters->number_of_entries(), (method->is_static() ? "static" : "receiver"),
method->signature()->as_C_string(), insts_size);
tty->print_cr("c2i argument handler starts at %p",entry->get_c2i_entry());
if (Verbose || PrintStubCode) {
address first_pc = entry->base_address();
if (first_pc != NULL) {
Disassembler::decode(first_pc, first_pc + insts_size);
tty->cr();
}
}
}
#endif
if (contains_all_checks || !VerifyAdapterCalls) {
_adapters->add(entry);
}
}
if (new_adapter != NULL) {
char blob_id[256];
jio_snprintf(blob_id,
sizeof(blob_id),
"%s(%s)@" PTR_FORMAT,
new_adapter->name(),
fingerprint->as_string(),
new_adapter->content_begin());
Forte::register_stub(blob_id, new_adapter->content_begin(),new_adapter->content_end());
if (JvmtiExport::should_post_dynamic_code_generated()) {
JvmtiExport::post_dynamic_code_generated(blob_id, new_adapter->content_begin(), new_adapter->content_end());
}
}
return entry;
}
address AdapterHandlerEntry::base_address() {
address base = _i2c_entry;
if (base == NULL) base = _c2i_entry;
assert(base <= _c2i_entry || _c2i_entry == NULL, "");
assert(base <= _c2i_unverified_entry || _c2i_unverified_entry == NULL, "");
return base;
}
void AdapterHandlerEntry::relocate(address new_base) {
address old_base = base_address();
assert(old_base != NULL, "");
ptrdiff_t delta = new_base - old_base;
if (_i2c_entry != NULL)
_i2c_entry += delta;
if (_c2i_entry != NULL)
_c2i_entry += delta;
if (_c2i_unverified_entry != NULL)
_c2i_unverified_entry += delta;
assert(base_address() == new_base, "");
}
void AdapterHandlerEntry::deallocate() {
delete _fingerprint;
#ifdef ASSERT
if (_saved_code) FREE_C_HEAP_ARRAY(unsigned char, _saved_code, mtCode);
#endif
}
#ifdef ASSERT
void AdapterHandlerEntry::save_code(unsigned char* buffer, int length) {
_saved_code = NEW_C_HEAP_ARRAY(unsigned char, length, mtCode);
_saved_code_length = length;
memcpy(_saved_code, buffer, length);
}
bool AdapterHandlerEntry::compare_code(unsigned char* buffer, int length) {
if (length != _saved_code_length) {
return false;
}
return (memcmp(buffer, _saved_code, length) == 0) ? true : false;
}
#endif
void AdapterHandlerLibrary::create_native_wrapper(methodHandle method) {
ResourceMark rm;
nmethod* nm = NULL;
assert(method->is_native(), "must be native");
assert(method->is_method_handle_intrinsic() ||
method->has_native_function(), "must have something valid to call!");
{
MutexLocker mu(AdapterHandlerLibrary_lock);
nm = method->code();
if (nm != NULL) {
return;
}
const int compile_id = CompileBroker::assign_compile_id(method, CompileBroker::standard_entry_bci);
assert(compile_id > 0, "Must generate native wrapper");
ResourceMark rm;
BufferBlob* buf = buffer_blob(); // the temporary code buffer in CodeCache
if (buf != NULL) {
CodeBuffer buffer(buf);
struct { double data[20]; } locs_buf;
buffer.insts()->initialize_shared_locs((relocInfo*)&locs_buf, sizeof(locs_buf) / sizeof(relocInfo));
MacroAssembler _masm(&buffer);
const int total_args_passed = method->size_of_parameters();
BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_args_passed);
VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed);
int i=0;
if( !method->is_static() ) // Pass in receiver first
sig_bt[i++] = T_OBJECT;
SignatureStream ss(method->signature());
for( ; !ss.at_return_type(); ss.next()) {
sig_bt[i++] = ss.type(); // Collect remaining bits of signature
if( ss.type() == T_LONG || ss.type() == T_DOUBLE )
sig_bt[i++] = T_VOID; // Longs & doubles take 2 Java slots
}
assert(i == total_args_passed, "");
BasicType ret_type = ss.type();
const bool is_outgoing = method->is_method_handle_intrinsic();
int comp_args_on_stack = SharedRuntime::java_calling_convention(sig_bt, regs, total_args_passed, is_outgoing);
nm = SharedRuntime::generate_native_wrapper(&_masm, method, compile_id, sig_bt, regs, ret_type);
if (nm != NULL) {
method->set_code(method, nm);
}
}
} // Unlock AdapterHandlerLibrary_lock
if (nm != NULL) {
if (PrintCompilation) {
ttyLocker ttyl;
CompileTask::print_compilation(tty, nm, method->is_static() ? "(static)" : "");
}
nm->post_compiled_method_load_event();
} else {
CompileBroker::handle_full_code_cache();
}
}
JRT_ENTRY_NO_ASYNC(void, SharedRuntime::block_for_jni_critical(JavaThread* thread))
assert(thread == JavaThread::current(), "must be");
if (thread->in_critical()) {
return;
}
GC_locker::lock_critical(thread);
GC_locker::unlock_critical(thread);
JRT_END
#ifdef HAVE_DTRACE_H
nmethod *AdapterHandlerLibrary::create_dtrace_nmethod(methodHandle method) {
ResourceMark rm;
nmethod* nm = NULL;
if (PrintCompilation) {
ttyLocker ttyl;
tty->print("--- n ");
method->print_short_name(tty);
if (method->is_static()) {
tty->print(" (static)");
}
tty->cr();
}
{
MutexLocker mu(AdapterHandlerLibrary_lock);
nm = method->code();
if (nm) {
return nm;
}
ResourceMark rm;
BufferBlob* buf = buffer_blob(); // the temporary code buffer in CodeCache
if (buf != NULL) {
CodeBuffer buffer(buf);
double locs_buf[20];
buffer.insts()->initialize_shared_locs(
(relocInfo*)locs_buf, sizeof(locs_buf) / sizeof(relocInfo));
MacroAssembler _masm(&buffer);
nm = SharedRuntime::generate_dtrace_nmethod(&_masm, method);
}
}
return nm;
}
void SharedRuntime::get_utf(oopDesc* src, address dst) {
typeArrayOop jlsValue = java_lang_String::value(src);
int jlsOffset = java_lang_String::offset(src);
int jlsLen = java_lang_String::length(src);
jchar* jlsPos = (jlsLen == 0) ? NULL :
jlsValue->char_at_addr(jlsOffset);
assert(TypeArrayKlass::cast(jlsValue->klass())->element_type() == T_CHAR, "compressed string");
(void) UNICODE::as_utf8(jlsPos, jlsLen, (char *)dst, max_dtrace_string_size);
}
#endif // ndef HAVE_DTRACE_H
int SharedRuntime::convert_ints_to_longints_argcnt(int in_args_count, BasicType* in_sig_bt) {
int argcnt = in_args_count;
if (CCallingConventionRequiresIntsAsLongs) {
for (int in = 0; in < in_args_count; in++) {
BasicType bt = in_sig_bt[in];
switch (bt) {
case T_BOOLEAN:
case T_CHAR:
case T_BYTE:
case T_SHORT:
case T_INT:
argcnt++;
break;
default:
break;
}
}
} else {
assert(0, "This should not be needed on this platform");
}
return argcnt;
}
void SharedRuntime::convert_ints_to_longints(int i2l_argcnt, int& in_args_count,
BasicType*& in_sig_bt, VMRegPair*& in_regs) {
if (CCallingConventionRequiresIntsAsLongs) {
VMRegPair *new_in_regs = NEW_RESOURCE_ARRAY(VMRegPair, i2l_argcnt);
BasicType *new_in_sig_bt = NEW_RESOURCE_ARRAY(BasicType, i2l_argcnt);
int argcnt = 0;
for (int in = 0; in < in_args_count; in++, argcnt++) {
BasicType bt = in_sig_bt[in];
VMRegPair reg = in_regs[in];
switch (bt) {
case T_BOOLEAN:
case T_CHAR:
case T_BYTE:
case T_SHORT:
case T_INT:
new_in_sig_bt[argcnt ] = T_LONG;
new_in_sig_bt[argcnt+1] = bt;
assert(reg.first()->is_valid() && !reg.second()->is_valid(), "");
new_in_regs[argcnt ].set2(reg.first());
new_in_regs[argcnt+1].set_bad();
argcnt++;
break;
default:
new_in_sig_bt[argcnt] = bt;
new_in_regs[argcnt] = reg;
break;
}
}
assert(argcnt == i2l_argcnt, "must match");
in_regs = new_in_regs;
in_sig_bt = new_in_sig_bt;
in_args_count = i2l_argcnt;
} else {
assert(0, "This should not be needed on this platform");
}
}
VMReg SharedRuntime::name_for_receiver() {
VMRegPair regs;
BasicType sig_bt = T_OBJECT;
(void) java_calling_convention(&sig_bt, ®s, 1, true);
return regs.first();
}
VMRegPair *SharedRuntime::find_callee_arguments(Symbol* sig, bool has_receiver, bool has_appendix, int* arg_size) {
char *s = sig->as_C_string();
int len = (int)strlen(s);
s++; len--; // Skip opening paren
BasicType *sig_bt = NEW_RESOURCE_ARRAY( BasicType, 256 );
VMRegPair *regs = NEW_RESOURCE_ARRAY( VMRegPair, 256 );
int cnt = 0;
if (has_receiver) {
sig_bt[cnt++] = T_OBJECT; // Receiver is argument 0; not in signature
}
while( *s != ')' ) { // Find closing right paren
switch( *s++ ) { // Switch on signature character
case 'B': sig_bt[cnt++] = T_BYTE; break;
case 'C': sig_bt[cnt++] = T_CHAR; break;
case 'D': sig_bt[cnt++] = T_DOUBLE; sig_bt[cnt++] = T_VOID; break;
case 'F': sig_bt[cnt++] = T_FLOAT; break;
case 'I': sig_bt[cnt++] = T_INT; break;
case 'J': sig_bt[cnt++] = T_LONG; sig_bt[cnt++] = T_VOID; break;
case 'S': sig_bt[cnt++] = T_SHORT; break;
case 'Z': sig_bt[cnt++] = T_BOOLEAN; break;
case 'V': sig_bt[cnt++] = T_VOID; break;
case 'L': // Oop
while( *s++ != ';' ) ; // Skip signature
sig_bt[cnt++] = T_OBJECT;
break;
case '[': { // Array
do { // Skip optional size
while( *s >= '0' && *s <= '9' ) s++;
} while( *s++ == '[' ); // Nested arrays?
if( s[-1] == 'L' )
while( *s++ != ';' ) ; // Skip signature
sig_bt[cnt++] = T_ARRAY;
break;
}
default : ShouldNotReachHere();
}
}
if (has_appendix) {
sig_bt[cnt++] = T_OBJECT;
}
assert( cnt < 256, "grow table size" );
int comp_args_on_stack;
comp_args_on_stack = java_calling_convention(sig_bt, regs, cnt, true);
if (comp_args_on_stack) {
for (int i = 0; i < cnt; i++) {
VMReg reg1 = regs[i].first();
if( reg1->is_stack()) {
reg1 = reg1->bias(out_preserve_stack_slots());
}
VMReg reg2 = regs[i].second();
if( reg2->is_stack()) {
reg2 = reg2->bias(out_preserve_stack_slots());
}
regs[i].set_pair(reg2, reg1);
}
}
return regs;
}
JRT_LEAF(intptr_t*, SharedRuntime::OSR_migration_begin( JavaThread *thread) )
frame fr = thread->last_frame();
assert( fr.is_interpreted_frame(), "" );
assert( fr.interpreter_frame_expression_stack_size()==0, "only handle empty stacks" );
int active_monitor_count = 0;
for( BasicObjectLock *kptr = fr.interpreter_frame_monitor_end();
kptr < fr.interpreter_frame_monitor_begin();
kptr = fr.next_monitor_in_interpreter_frame(kptr) ) {
if( kptr->obj() != NULL ) active_monitor_count++;
}
Method* moop = fr.interpreter_frame_method();
int max_locals = moop->max_locals();
int buf_size_words = max_locals + active_monitor_count*2;
intptr_t *buf = NEW_C_HEAP_ARRAY(intptr_t,buf_size_words, mtCode);
assert( sizeof(HeapWord)==sizeof(intptr_t), "fix this code");
Copy::disjoint_words((HeapWord*)fr.interpreter_frame_local_at(max_locals-1),
(HeapWord*)&buf[0],
max_locals);
int i = max_locals;
for( BasicObjectLock *kptr2 = fr.interpreter_frame_monitor_end();
kptr2 < fr.interpreter_frame_monitor_begin();
kptr2 = fr.next_monitor_in_interpreter_frame(kptr2) ) {
if( kptr2->obj() != NULL) { // Avoid 'holes' in the monitor array
BasicLock *lock = kptr2->lock();
if (lock->displaced_header()->is_unlocked())
ObjectSynchronizer::inflate_helper(kptr2->obj());
buf[i++] = (intptr_t)lock->displaced_header();
buf[i++] = cast_from_oop<intptr_t>(kptr2->obj());
}
}
assert( i - max_locals == active_monitor_count*2, "found the expected number of monitors" );
return buf;
JRT_END
JRT_LEAF(void, SharedRuntime::OSR_migration_end( intptr_t* buf) )
FREE_C_HEAP_ARRAY(intptr_t,buf, mtCode);
JRT_END
bool AdapterHandlerLibrary::contains(CodeBlob* b) {
AdapterHandlerTableIterator iter(_adapters);
while (iter.has_next()) {
AdapterHandlerEntry* a = iter.next();
if ( b == CodeCache::find_blob(a->get_i2c_entry()) ) return true;
}
return false;
}
void AdapterHandlerLibrary::print_handler_on(outputStream* st, CodeBlob* b) {
AdapterHandlerTableIterator iter(_adapters);
while (iter.has_next()) {
AdapterHandlerEntry* a = iter.next();
if (b == CodeCache::find_blob(a->get_i2c_entry())) {
st->print("Adapter for signature: ");
a->print_adapter_on(tty);
return;
}
}
assert(false, "Should have found handler");
}
void AdapterHandlerEntry::print_adapter_on(outputStream* st) const {
st->print_cr("AHE@" INTPTR_FORMAT ": %s i2c: " INTPTR_FORMAT " c2i: " INTPTR_FORMAT " c2iUV: " INTPTR_FORMAT,
(intptr_t) this, fingerprint()->as_string(),
get_i2c_entry(), get_c2i_entry(), get_c2i_unverified_entry());
}
#ifndef PRODUCT
void AdapterHandlerLibrary::print_statistics() {
_adapters->print_statistics();
}
#endif /* PRODUCT */
C:\hotspot-69087d08d473\src\share\vm/runtime/sharedRuntime.hpp
#ifndef SHARE_VM_RUNTIME_SHAREDRUNTIME_HPP
#define SHARE_VM_RUNTIME_SHAREDRUNTIME_HPP
#include "interpreter/bytecodeHistogram.hpp"
#include "interpreter/bytecodeTracer.hpp"
#include "interpreter/linkResolver.hpp"
#include "memory/allocation.hpp"
#include "memory/resourceArea.hpp"
#include "runtime/threadLocalStorage.hpp"
#include "utilities/hashtable.hpp"
#include "utilities/macros.hpp"
class AdapterHandlerEntry;
class AdapterHandlerTable;
class AdapterFingerPrint;
class vframeStream;
class SharedRuntime: AllStatic {
friend class VMStructs;
private:
static methodHandle resolve_sub_helper(JavaThread *thread,
bool is_virtual,
bool is_optimized, TRAPS);
static RuntimeStub* _wrong_method_blob;
static RuntimeStub* _wrong_method_abstract_blob;
static RuntimeStub* _ic_miss_blob;
static RuntimeStub* _resolve_opt_virtual_call_blob;
static RuntimeStub* _resolve_virtual_call_blob;
static RuntimeStub* _resolve_static_call_blob;
static DeoptimizationBlob* _deopt_blob;
static SafepointBlob* _polling_page_vectors_safepoint_handler_blob;
static SafepointBlob* _polling_page_safepoint_handler_blob;
static SafepointBlob* _polling_page_return_handler_blob;
#ifdef COMPILER2
static UncommonTrapBlob* _uncommon_trap_blob;
#endif // COMPILER2
#ifndef PRODUCT
static int _nof_megamorphic_calls; // total # of megamorphic calls (through vtable)
#endif // !PRODUCT
private:
enum { POLL_AT_RETURN, POLL_AT_LOOP, POLL_AT_VECTOR_LOOP };
static SafepointBlob* generate_handler_blob(address call_ptr, int poll_type);
static RuntimeStub* generate_resolve_blob(address destination, const char* name);
public:
static void generate_stubs(void);
enum { max_dtrace_string_size = 256 };
static jlong lmul(jlong y, jlong x);
static jlong ldiv(jlong y, jlong x);
static jlong lrem(jlong y, jlong x);
static jfloat frem(jfloat x, jfloat y);
static jdouble drem(jdouble x, jdouble y);
#ifdef __SOFTFP__
static jfloat fadd(jfloat x, jfloat y);
static jfloat fsub(jfloat x, jfloat y);
static jfloat fmul(jfloat x, jfloat y);
static jfloat fdiv(jfloat x, jfloat y);
static jdouble dadd(jdouble x, jdouble y);
static jdouble dsub(jdouble x, jdouble y);
static jdouble dmul(jdouble x, jdouble y);
static jdouble ddiv(jdouble x, jdouble y);
#endif // __SOFTFP__
static jint f2i (jfloat x);
static jlong f2l (jfloat x);
static jint d2i (jdouble x);
static jlong d2l (jdouble x);
static jfloat d2f (jdouble x);
static jfloat l2f (jlong x);
static jdouble l2d (jlong x);
#ifdef __SOFTFP__
static jfloat i2f (jint x);
static jdouble i2d (jint x);
static jdouble f2d (jfloat x);
#endif // __SOFTFP__
static jdouble dsin(jdouble x);
static jdouble dcos(jdouble x);
static jdouble dtan(jdouble x);
static jdouble dlog(jdouble x);
static jdouble dlog10(jdouble x);
static jdouble dexp(jdouble x);
static jdouble dpow(jdouble x, jdouble y);
#if defined(__SOFTFP__) || defined(E500V2)
static double dabs(double f);
#endif
#if defined(__SOFTFP__) || defined(PPC32)
static double dsqrt(double f);
#endif
static void montgomery_multiply(jint *a_ints, jint *b_ints, jint *n_ints,
jint len, jlong inv, jint *m_ints);
static void montgomery_square(jint *a_ints, jint *n_ints,
jint len, jlong inv, jint *m_ints);
#ifdef __SOFTFP__
static int fcmpl(float x, float y);
static int fcmpg(float x, float y);
static int dcmpl(double x, double y);
static int dcmpg(double x, double y);
static int unordered_fcmplt(float x, float y);
static int unordered_dcmplt(double x, double y);
static int unordered_fcmple(float x, float y);
static int unordered_dcmple(double x, double y);
static int unordered_fcmpge(float x, float y);
static int unordered_dcmpge(double x, double y);
static int unordered_fcmpgt(float x, float y);
static int unordered_dcmpgt(double x, double y);
static float fneg(float f);
static double dneg(double f);
#endif
static address raw_exception_handler_for_return_address(JavaThread* thread, address return_address);
static address exception_handler_for_return_address(JavaThread* thread, address return_address);
#if INCLUDE_ALL_GCS
static void g1_wb_pre(oopDesc* orig, JavaThread *thread);
static void g1_wb_post(void* card_addr, JavaThread* thread);
#endif // INCLUDE_ALL_GCS
static address compute_compiled_exc_handler(nmethod* nm, address ret_pc, Handle& exception,
bool force_unwind, bool top_frame_only, bool& recursive_exception_occurred);
enum ImplicitExceptionKind {
IMPLICIT_NULL,
IMPLICIT_DIVIDE_BY_ZERO,
STACK_OVERFLOW
};
static void throw_AbstractMethodError(JavaThread* thread);
static void throw_IncompatibleClassChangeError(JavaThread* thread);
static void throw_ArithmeticException(JavaThread* thread);
static void throw_NullPointerException(JavaThread* thread);
static void throw_NullPointerException_at_call(JavaThread* thread);
static void throw_StackOverflowError(JavaThread* thread);
static address continuation_for_implicit_exception(JavaThread* thread,
address faulting_pc,
ImplicitExceptionKind exception_kind);
static address get_poll_stub(address pc);
static address get_ic_miss_stub() {
assert(_ic_miss_blob!= NULL, "oops");
return _ic_miss_blob->entry_point();
}
static address get_handle_wrong_method_stub() {
assert(_wrong_method_blob!= NULL, "oops");
return _wrong_method_blob->entry_point();
}
static address get_handle_wrong_method_abstract_stub() {
assert(_wrong_method_abstract_blob!= NULL, "oops");
return _wrong_method_abstract_blob->entry_point();
}
#ifdef COMPILER2
static void generate_uncommon_trap_blob(void);
static UncommonTrapBlob* uncommon_trap_blob() { return _uncommon_trap_blob; }
#endif // COMPILER2
static address get_resolve_opt_virtual_call_stub(){
assert(_resolve_opt_virtual_call_blob != NULL, "oops");
return _resolve_opt_virtual_call_blob->entry_point();
}
static address get_resolve_virtual_call_stub() {
assert(_resolve_virtual_call_blob != NULL, "oops");
return _resolve_virtual_call_blob->entry_point();
}
static address get_resolve_static_call_stub() {
assert(_resolve_static_call_blob != NULL, "oops");
return _resolve_static_call_blob->entry_point();
}
static SafepointBlob* polling_page_return_handler_blob() { return _polling_page_return_handler_blob; }
static SafepointBlob* polling_page_safepoint_handler_blob() { return _polling_page_safepoint_handler_blob; }
static SafepointBlob* polling_page_vectors_safepoint_handler_blob() { return _polling_page_vectors_safepoint_handler_blob; }
#ifndef PRODUCT
static address nof_megamorphic_calls_addr() { return (address)&_nof_megamorphic_calls; }
#endif // PRODUCT
static void throw_and_post_jvmti_exception(JavaThread *thread, Handle h_exception);
static void throw_and_post_jvmti_exception(JavaThread *thread, Symbol* name, const char *message = NULL);
static int rc_trace_method_entry(JavaThread* thread, Method* m);
static address native_method_throw_unsatisfied_link_error_entry();
static address native_method_throw_unsupported_operation_exception_entry();
static intptr_t trace_bytecode(JavaThread* thread, intptr_t preserve_this_value, intptr_t tos, intptr_t tos2) PRODUCT_RETURN0;
static void yield_all(JavaThread* thread, int attempts = 0);
static oop retrieve_receiver( Symbol* sig, frame caller );
static void register_finalizer(JavaThread* thread, oopDesc* obj);
static int dtrace_object_alloc(oopDesc* o, int size);
static int dtrace_object_alloc_base(Thread* thread, oopDesc* o, int size);
static int dtrace_method_entry(JavaThread* thread, Method* m);
static int dtrace_method_exit(JavaThread* thread, Method* m);
static jlong get_java_tid(Thread* thread);
static void reguard_yellow_pages();
static char* generate_class_cast_message(JavaThread* thr, const char* name);
static char* generate_class_cast_message(const char* name, const char* klass,
const char* gripe = " cannot be cast to ");
static methodHandle resolve_helper(JavaThread *thread,
bool is_virtual,
bool is_optimized, TRAPS);
private:
static void generate_deopt_blob(void);
public:
static DeoptimizationBlob* deopt_blob(void) { return _deopt_blob; }
static methodHandle reresolve_call_site(JavaThread *thread, TRAPS);
static methodHandle handle_ic_miss_helper(JavaThread* thread, TRAPS);
static methodHandle find_callee_method(JavaThread* thread, TRAPS);
private:
static Handle find_callee_info(JavaThread* thread,
Bytecodes::Code& bc,
CallInfo& callinfo, TRAPS);
static Handle find_callee_info_helper(JavaThread* thread,
vframeStream& vfst,
Bytecodes::Code& bc,
CallInfo& callinfo, TRAPS);
static address clean_virtual_call_entry();
static address clean_opt_virtual_call_entry();
static address clean_static_call_entry();
public:
static int java_calling_convention(const BasicType* sig_bt, VMRegPair* regs, int total_args_passed, int is_outgoing);
static void check_member_name_argument_is_last_argument(methodHandle method,
const BasicType* sig_bt,
const VMRegPair* regs) NOT_DEBUG_RETURN;
static int c_calling_convention(const BasicType *sig_bt, VMRegPair *regs, VMRegPair *regs2,
int total_args_passed);
static int convert_ints_to_longints_argcnt(int in_args_count, BasicType* in_sig_bt);
static void convert_ints_to_longints(int i2l_argcnt, int& in_args_count,
BasicType*& in_sig_bt, VMRegPair*& in_regs);
static AdapterHandlerEntry* generate_i2c2i_adapters(MacroAssembler *_masm,
int total_args_passed,
int max_arg,
const BasicType *sig_bt,
const VMRegPair *regs,
AdapterFingerPrint* fingerprint);
static intptr_t* OSR_migration_begin( JavaThread *thread);
static void OSR_migration_end ( intptr_t* buf);
static VMRegPair* find_callee_arguments(Symbol* sig, bool has_receiver, bool has_appendix, int *arg_size);
static VMReg name_for_receiver();
static uint out_preserve_stack_slots();
static bool is_wide_vector(int size);
static void save_native_result(MacroAssembler *_masm, BasicType ret_type, int frame_slots );
static void restore_native_result(MacroAssembler *_masm, BasicType ret_type, int frame_slots );
static nmethod* generate_native_wrapper(MacroAssembler* masm,
methodHandle method,
int compile_id,
BasicType* sig_bt,
VMRegPair* regs,
BasicType ret_type );
static void block_for_jni_critical(JavaThread* thread);
#ifdef HAVE_DTRACE_H
static nmethod *generate_dtrace_nmethod(MacroAssembler* masm,
methodHandle method);
static void get_utf(oopDesc* src, address dst);
#endif // def HAVE_DTRACE_H
static void fixup_callers_callsite(Method* moop, address ret_pc);
static void complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* thread);
static void complete_monitor_unlocking_C(oopDesc* obj, BasicLock* lock);
static address resolve_static_call_C (JavaThread *thread);
static address resolve_virtual_call_C (JavaThread *thread);
static address resolve_opt_virtual_call_C(JavaThread *thread);
static void slow_arraycopy_C(oopDesc* src, jint src_pos,
oopDesc* dest, jint dest_pos,
jint length, JavaThread* thread);
static address handle_wrong_method(JavaThread* thread);
static address handle_wrong_method_abstract(JavaThread* thread);
static address handle_wrong_method_ic_miss(JavaThread* thread);
#ifndef PRODUCT
private:
enum { maxICmiss_count = 100 };
static int _ICmiss_index; // length of IC miss histogram
static int _ICmiss_count[maxICmiss_count]; // miss counts
static address _ICmiss_at[maxICmiss_count]; // miss addresses
static void trace_ic_miss(address at);
public:
static int _monitor_enter_ctr; // monitor enter slow
static int _monitor_exit_ctr; // monitor exit slow
static int _throw_null_ctr; // throwing a null-pointer exception
static int _ic_miss_ctr; // total # of IC misses
static int _wrong_method_ctr;
static int _resolve_static_ctr;
static int _resolve_virtual_ctr;
static int _resolve_opt_virtual_ctr;
static int _implicit_null_throws;
static int _implicit_div0_throws;
static int _jbyte_array_copy_ctr; // Slow-path byte array copy
static int _jshort_array_copy_ctr; // Slow-path short array copy
static int _jint_array_copy_ctr; // Slow-path int array copy
static int _jlong_array_copy_ctr; // Slow-path long array copy
static int _oop_array_copy_ctr; // Slow-path oop array copy
static int _checkcast_array_copy_ctr; // Slow-path oop array copy, with cast
static int _unsafe_array_copy_ctr; // Slow-path includes alignment checks
static int _generic_array_copy_ctr; // Slow-path includes type decoding
static int _slow_array_copy_ctr; // Slow-path failed out to a method call
static int _new_instance_ctr; // 'new' object requires GC
static int _new_array_ctr; // 'new' array requires GC
static int _multi1_ctr, _multi2_ctr, _multi3_ctr, _multi4_ctr, _multi5_ctr;
static int _find_handler_ctr; // find exception handler
static int _rethrow_ctr; // rethrow exception
static int _mon_enter_stub_ctr; // monitor enter stub
static int _mon_exit_stub_ctr; // monitor exit stub
static int _mon_enter_ctr; // monitor enter slow
static int _mon_exit_ctr; // monitor exit slow
static int _partial_subtype_ctr; // SubRoutines::partial_subtype_check
static int _nof_normal_calls; // total # of calls
static int _nof_optimized_calls; // total # of statically-bound calls
static int _nof_inlined_calls; // total # of inlined normal calls
static int _nof_static_calls; // total # of calls to static methods or super methods (invokespecial)
static int _nof_inlined_static_calls; // total # of inlined static calls
static int _nof_interface_calls; // total # of compiled calls
static int _nof_optimized_interface_calls; // total # of statically-bound interface calls
static int _nof_inlined_interface_calls; // total # of inlined interface calls
static int _nof_megamorphic_interface_calls;// total # of megamorphic interface calls
static int _nof_removable_exceptions; // total # of exceptions that could be replaced by branches due to inlining
public: // for compiler
static address nof_normal_calls_addr() { return (address)&_nof_normal_calls; }
static address nof_optimized_calls_addr() { return (address)&_nof_optimized_calls; }
static address nof_inlined_calls_addr() { return (address)&_nof_inlined_calls; }
static address nof_static_calls_addr() { return (address)&_nof_static_calls; }
static address nof_inlined_static_calls_addr() { return (address)&_nof_inlined_static_calls; }
static address nof_interface_calls_addr() { return (address)&_nof_interface_calls; }
static address nof_optimized_interface_calls_addr() { return (address)&_nof_optimized_interface_calls; }
static address nof_inlined_interface_calls_addr() { return (address)&_nof_inlined_interface_calls; }
static address nof_megamorphic_interface_calls_addr() { return (address)&_nof_megamorphic_interface_calls; }
static void print_call_statistics(int comp_total);
static void print_statistics();
static void print_ic_miss_histogram();
#endif // PRODUCT
};
class AdapterHandlerEntry : public BasicHashtableEntry<mtCode> {
friend class AdapterHandlerTable;
private:
AdapterFingerPrint* _fingerprint;
address _i2c_entry;
address _c2i_entry;
address _c2i_unverified_entry;
#ifdef ASSERT
unsigned char* _saved_code;
int _saved_code_length;
#endif
void init(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry, address c2i_unverified_entry) {
_fingerprint = fingerprint;
_i2c_entry = i2c_entry;
_c2i_entry = c2i_entry;
_c2i_unverified_entry = c2i_unverified_entry;
#ifdef ASSERT
_saved_code = NULL;
_saved_code_length = 0;
#endif
}
void deallocate();
AdapterHandlerEntry();
public:
address get_i2c_entry() const { return _i2c_entry; }
address get_c2i_entry() const { return _c2i_entry; }
address get_c2i_unverified_entry() const { return _c2i_unverified_entry; }
address base_address();
void relocate(address new_base);
AdapterFingerPrint* fingerprint() const { return _fingerprint; }
AdapterHandlerEntry* next() {
return (AdapterHandlerEntry*)BasicHashtableEntry<mtCode>::next();
}
#ifdef ASSERT
void save_code (unsigned char* code, int length);
bool compare_code(unsigned char* code, int length);
#endif
void print_adapter_on(outputStream* st) const;
};
class AdapterHandlerLibrary: public AllStatic {
private:
static BufferBlob* _buffer; // the temporary code buffer in CodeCache
static AdapterHandlerTable* _adapters;
static AdapterHandlerEntry* _abstract_method_handler;
static BufferBlob* buffer_blob();
static void initialize();
public:
static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint,
address i2c_entry, address c2i_entry, address c2i_unverified_entry);
static void create_native_wrapper(methodHandle method);
static AdapterHandlerEntry* get_adapter(methodHandle method);
#ifdef HAVE_DTRACE_H
static nmethod* create_dtrace_nmethod (methodHandle method);
#endif // HAVE_DTRACE_H
static void print_handler(CodeBlob* b) { print_handler_on(tty, b); }
static void print_handler_on(outputStream* st, CodeBlob* b);
static bool contains(CodeBlob* b);
#ifndef PRODUCT
static void print_statistics();
#endif /* PRODUCT */
};
#endif // SHARE_VM_RUNTIME_SHAREDRUNTIME_HPP
C:\hotspot-69087d08d473\src\share\vm/runtime/sharedRuntimeMath.hpp
#ifndef SHARE_VM_RUNTIME_SHAREDRUNTIMEMATH_HPP
#define SHARE_VM_RUNTIME_SHAREDRUNTIMEMATH_HPP
#include <math.h>
typedef union {
double d;
struct {
#ifdef VM_LITTLE_ENDIAN
int lo;
int hi;
#else
int hi;
int lo;
#endif
} split;
} DoubleIntConv;
static inline int high(double d) {
DoubleIntConv x;
x.d = d;
return x.split.hi;
}
static inline int low(double d) {
DoubleIntConv x;
x.d = d;
return x.split.lo;
}
static inline void set_high(double* d, int high) {
DoubleIntConv conv;
conv.d = *d;
conv.split.hi = high;
}
static inline void set_low(double* d, int low) {
DoubleIntConv conv;
conv.d = *d;
conv.split.lo = low;
}
static double copysignA(double x, double y) {
DoubleIntConv convX;
convX.d = x;
convX.split.hi = (convX.split.hi & 0x7fffffff) | (high(y) & 0x80000000);
return convX.d;
}
static const double
two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */
twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */
hugeX = 1.0e+300,
tiny = 1.0e-300;
static double scalbnA(double x, int n) {
int k,hx,lx;
hx = high(x);
lx = low(x);
k = (hx&0x7ff00000)>>20; /* extract exponent */
if (k==0) { /* 0 or subnormal x */
if ((lx|(hx&0x7fffffff))==0) return x; /* +-0 */
x *= two54;
hx = high(x);
k = ((hx&0x7ff00000)>>20) - 54;
if (n< -50000) return tiny*x; /*underflow*/
}
if (k==0x7ff) return x+x; /* NaN or Inf */
k = k+n;
if (k > 0x7fe) return hugeX*copysignA(hugeX,x); /* overflow */
if (k > 0) { /* normal result */
set_high(&x, (hx&0x800fffff)|(k<<20));
return x;
}
if (k <= -54) {
if (n > 50000) /* in case integer overflow in n+k */
return hugeX*copysignA(hugeX,x); /*overflow*/
else return tiny*copysignA(tiny,x); /*underflow*/
}
k += 54; /* subnormal result */
set_high(&x, (hx&0x800fffff)|(k<<20));
return x*twom54;
}
#endif // SHARE_VM_RUNTIME_SHAREDRUNTIMEMATH_HPP
C:\hotspot-69087d08d473\src\share\vm/runtime/sharedRuntimeTrans.cpp
#include "precompiled.hpp"
#include "prims/jni.h"
#include "runtime/interfaceSupport.hpp"
#include "runtime/sharedRuntime.hpp"
#ifdef WIN32
# pragma warning( disable: 4748 ) // /GS can not protect parameters and local variables from local buffer overrun because optimizations are disabled in function
# pragma optimize ( "", off )
#endif
#include "runtime/sharedRuntimeMath.hpp"
static const double
ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */
ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */
Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */
Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */
Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */
Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */
Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */
Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */
Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */
static double zero = 0.0;
static double __ieee754_log(double x) {
double hfsq,f,s,z,R,w,t1,t2,dk;
int k,hx,i,j;
unsigned lx;
hx = high(x); /* high word of x */
lx = low(x); /* low word of x */
k=0;
if (hx < 0x00100000) { /* x < 2**-1022 */
if (((hx&0x7fffffff)|lx)==0)
return -two54/zero; /* log(+-0)=-inf */
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
k -= 54; x *= two54; /* subnormal number, scale up x */
hx = high(x); /* high word of x */
}
if (hx >= 0x7ff00000) return x+x;
k += (hx>>20)-1023;
hx &= 0x000fffff;
i = (hx+0x95f64)&0x100000;
set_high(&x, hx|(i^0x3ff00000)); /* normalize x or x/2 */
k += (i>>20);
f = x-1.0;
if((0x000fffff&(2+hx))<3) { /* |f| < 2**-20 */
if(f==zero) {
if (k==0) return zero;
else {dk=(double)k; return dk*ln2_hi+dk*ln2_lo;}
}
R = f*f*(0.5-0.33333333333333333*f);
if(k==0) return f-R; else {dk=(double)k;
return dk*ln2_hi-((R-dk*ln2_lo)-f);}
}
s = f/(2.0+f);
dk = (double)k;
z = s*s;
i = hx-0x6147a;
w = z*z;
j = 0x6b851-hx;
t1= w*(Lg2+w*(Lg4+w*Lg6));
t2= z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7)));
i |= j;
R = t2+t1;
if(i>0) {
hfsq=0.5*f*f;
if(k==0) return f-(hfsq-s*(hfsq+R)); else
return dk*ln2_hi-((hfsq-(s*(hfsq+R)+dk*ln2_lo))-f);
} else {
if(k==0) return f-s*(f-R); else
return dk*ln2_hi-((s*(f-R)-dk*ln2_lo)-f);
}
}
JRT_LEAF(jdouble, SharedRuntime::dlog(jdouble x))
return __ieee754_log(x);
JRT_END
static const double
ivln10 = 4.34294481903251816668e-01, /* 0x3FDBCB7B, 0x1526E50E */
log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */
log10_2lo = 3.69423907715893078616e-13; /* 0x3D59FEF3, 0x11F12B36 */
static double __ieee754_log10(double x) {
double y,z;
int i,k,hx;
unsigned lx;
hx = high(x); /* high word of x */
lx = low(x); /* low word of x */
k=0;
if (hx < 0x00100000) { /* x < 2**-1022 */
if (((hx&0x7fffffff)|lx)==0)
return -two54/zero; /* log(+-0)=-inf */
if (hx<0) return (x-x)/zero; /* log(-#) = NaN */
k -= 54; x *= two54; /* subnormal number, scale up x */
hx = high(x); /* high word of x */
}
if (hx >= 0x7ff00000) return x+x;
k += (hx>>20)-1023;
i = ((unsigned)k&0x80000000)>>31;
hx = (hx&0x000fffff)|((0x3ff-i)<<20);
y = (double)(k+i);
set_high(&x, hx);
z = y*log10_2lo + ivln10*__ieee754_log(x);
return z+y*log10_2hi;
}
JRT_LEAF(jdouble, SharedRuntime::dlog10(jdouble x))
return __ieee754_log10(x);
JRT_END
static const double
one = 1.0,
halF[2] = {0.5,-0.5,},
twom1000= 9.33263618503218878990e-302, /* 2**-1000=0x01700000,0*/
o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */
u_threshold= -7.45133219101941108420e+02, /* 0xc0874910, 0xD52D3051 */
ln2HI[2] ={ 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */
-6.93147180369123816490e-01,},/* 0xbfe62e42, 0xfee00000 */
ln2LO[2] ={ 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */
-1.90821492927058770002e-10,},/* 0xbdea39ef, 0x35793c76 */
invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */
P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */
P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */
P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */
P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */
P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */
static double __ieee754_exp(double x) {
double y,hi=0,lo=0,c,t;
int k=0,xsb;
unsigned hx;
hx = high(x); /* high word of x */
xsb = (hx>>31)&1; /* sign bit of x */
hx &= 0x7fffffff; /* high word of |x| */
if(hx >= 0x40862E42) { /* if |x|>=709.78... */
if(hx>=0x7ff00000) {
if(((hx&0xfffff)|low(x))!=0)
return x+x; /* NaN */
else return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */
}
if(x > o_threshold) return hugeX*hugeX; /* overflow */
if(x < u_threshold) return twom1000*twom1000; /* underflow */
}
if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */
if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */
hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb;
} else {
k = (int)(invln2*x+halF[xsb]);
t = k;
hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */
lo = t*ln2LO[0];
}
x = hi - lo;
}
else if(hx < 0x3e300000) { /* when |x|<2**-28 */
if(hugeX+x>one) return one+x;/* trigger inexact */
}
else k = 0;
t = x*x;
c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
if(k==0) return one-((x*c)/(c-2.0)-x);
else y = one-((lo-(x*c)/(2.0-c))-hi);
if(k >= -1021) {
set_high(&y, high(y) + (k<<20)); /* add k to y's exponent */
return y;
} else {
set_high(&y, high(y) + ((k+1000)<<20)); /* add k to y's exponent */
return y*twom1000;
}
}
JRT_LEAF(jdouble, SharedRuntime::dexp(jdouble x))
return __ieee754_exp(x);
JRT_END
static const double
bp[] = {1.0, 1.5,},
dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */
dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */
zeroX = 0.0,
two = 2.0,
two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */
L1X = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */
L2X = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */
L3X = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */
L4X = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */
L5X = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */
L6X = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */
lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */
lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */
ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */
cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */
cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */
cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/
ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */
ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/
ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
double __ieee754_pow(double x, double y) {
double z,ax,z_h,z_l,p_h,p_l;
double y1,t1,t2,r,s,t,u,v,w;
int i0,i1,i,j,k,yisint,n;
int hx,hy,ix,iy;
unsigned lx,ly;
i0 = ((*(int*)&one)>>29)^1; i1=1-i0;
hx = high(x); lx = low(x);
hy = high(y); ly = low(y);
ix = hx&0x7fffffff; iy = hy&0x7fffffff;
if((iy|ly)==0) return one;
if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) ||
iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0)))
return x+y;
yisint = 0;
if(hx<0) {
if(iy>=0x43400000) yisint = 2; /* even integer y */
else if(iy>=0x3ff00000) {
k = (iy>>20)-0x3ff; /* exponent */
if(k>20) {
j = ly>>(52-k);
if((unsigned)(j<<(52-k))==ly) yisint = 2-(j&1);
} else if(ly==0) {
j = iy>>(20-k);
if((j<<(20-k))==iy) yisint = 2-(j&1);
}
}
}
if(ly==0) {
if (iy==0x7ff00000) { /* y is +-inf */
if(((ix-0x3ff00000)|lx)==0)
return y - y; /* inf**+-1 is NaN */
else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */
return (hy>=0)? y: zeroX;
else /* (|x|<1)**-,+inf = inf,0 */
return (hy<0)?-y: zeroX;
}
if(iy==0x3ff00000) { /* y is +-1 */
if(hy<0) return one/x; else return x;
}
if(hy==0x40000000) return x*x; /* y is 2 */
if(hy==0x3fe00000) { /* y is 0.5 */
if(hx>=0) /* x >= +0 */
return sqrt(x);
}
}
ax = fabsd(x);
if(lx==0) {
if(ix==0x7ff00000||ix==0||ix==0x3ff00000){
z = ax; /*x is +-0,+-inf,+-1*/
if(hy<0) z = one/z; /* z = (1/|x|) */
if(hx<0) {
if(((ix-0x3ff00000)|yisint)==0) {
#ifdef CAN_USE_NAN_DEFINE
z = NAN;
#else
z = (z-z)/(z-z); /* (-1)**non-int is NaN */
#endif
} else if(yisint==1)
z = -1.0*z; /* (x<0)**odd = -(|x|**odd) */
}
return z;
}
}
n = (hx>>31)+1;
if((n|yisint)==0)
#ifdef CAN_USE_NAN_DEFINE
return NAN;
#else
return (x-x)/(x-x);
#endif
s = one; /* s (sign of result -ve**odd) = -1 else = 1 */
if((n|(yisint-1))==0) s = -one;/* (-ve)**(odd int) */
if(iy>0x41e00000) { /* if |y| > 2**31 */
if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */
if(ix<=0x3fefffff) return (hy<0)? hugeX*hugeX:tiny*tiny;
if(ix>=0x3ff00000) return (hy>0)? hugeX*hugeX:tiny*tiny;
}
if(ix<0x3fefffff) return (hy<0)? s*hugeX*hugeX:s*tiny*tiny;
if(ix>0x3ff00000) return (hy>0)? s*hugeX*hugeX:s*tiny*tiny;
log(x) by x-x^2/2+x^3/3-x^4/4 */
t = ax-one; /* t has 20 trailing zeros */
w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25));
u = ivln2_h*t; /* ivln2_h has 21 sig. bits */
v = t*ivln2_l-w*ivln2;
t1 = u+v;
set_low(&t1, 0);
t2 = v-(t1-u);
} else {
double ss,s2,s_h,s_l,t_h,t_l;
n = 0;
if(ix<0x00100000)
{ax *= two53; n -= 53; ix = high(ax); }
n += ((ix)>>20)-0x3ff;
j = ix&0x000fffff;
ix = j|0x3ff00000; /* normalize ix */
if(j<=0x3988E) k=0; /* |x|<sqrt(3/2) */
else if(j<0xBB67A) k=1; /* |x|<sqrt(3) */
else {k=0;n+=1;ix -= 0x00100000;}
set_high(&ax, ix);
u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */
v = one/(ax+bp[k]);
ss = u*v;
s_h = ss;
set_low(&s_h, 0);
t_h = zeroX;
set_high(&t_h, ((ix>>1)|0x20000000)+0x00080000+(k<<18));
t_l = ax - (t_h-bp[k]);
s_l = v*((u-s_h*t_h)-s_h*t_l);
s2 = ss*ss;
r = s2*s2*(L1X+s2*(L2X+s2*(L3X+s2*(L4X+s2*(L5X+s2*L6X)))));
r += s_l*(s_h+ss);
s2 = s_h*s_h;
t_h = 3.0+s2+r;
set_low(&t_h, 0);
t_l = r-((t_h-3.0)-s2);
u = s_h*t_h;
v = s_l*t_h+t_l*ss;
p_h = u+v;
set_low(&p_h, 0);
p_l = v-(p_h-u);
z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */
z_l = cp_l*p_h+p_l*cp+dp_l[k];
t = (double)n;
t1 = (((z_h+z_l)+dp_h[k])+t);
set_low(&t1, 0);
t2 = z_l-(((t1-t)-dp_h[k])-z_h);
}
y1 = y;
set_low(&y1, 0);
p_l = (y-y1)*t1+y*t2;
p_h = y1*t1;
z = p_l+p_h;
j = high(z);
i = low(z);
if (j>=0x40900000) { /* z >= 1024 */
if(((j-0x40900000)|i)!=0) /* if z > 1024 */
return s*hugeX*hugeX; /* overflow */
else {
if(p_l+ovt>z-p_h) return s*hugeX*hugeX; /* overflow */
}
} else if((j&0x7fffffff)>=0x4090cc00 ) { /* z <= -1075 */
if(((j-0xc090cc00)|i)!=0) /* z < -1075 */
return s*tiny*tiny; /* underflow */
else {
if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */
}
}
i = j&0x7fffffff;
k = (i>>20)-0x3ff;
n = 0;
if(i>0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */
n = j+(0x00100000>>(k+1));
k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */
t = zeroX;
set_high(&t, (n&~(0x000fffff>>k)));
n = ((n&0x000fffff)|0x00100000)>>(20-k);
if(j<0) n = -n;
p_h -= t;
}
t = p_l+p_h;
set_low(&t, 0);
u = t*lg2_h;
v = (p_l-(t-p_h))*lg2+t*lg2_l;
z = u+v;
w = v-(z-u);
t = z*z;
t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5))));
r = (z*t1)/(t1-two)-(w+z*w);
z = one-(r-z);
j = high(z);
j += (n<<20);
if((j>>20)<=0) z = scalbnA(z,n); /* subnormal output */
else set_high(&z, high(z) + (n<<20));
return s*z;
}
JRT_LEAF(jdouble, SharedRuntime::dpow(jdouble x, jdouble y))
return __ieee754_pow(x, y);
JRT_END
#ifdef WIN32
# pragma optimize ( "", on )
#endif
C:\hotspot-69087d08d473\src\share\vm/runtime/sharedRuntimeTrig.cpp
#include "precompiled.hpp"
#include "prims/jni.h"
#include "runtime/interfaceSupport.hpp"
#include "runtime/sharedRuntime.hpp"
#ifdef WIN32
# pragma optimize ( "", off )
#endif
#if defined(WIN32) && (defined(_MSC_VER) && (_MSC_VER >= 1600))
#define SAFEBUF __declspec(safebuffers)
#else
#define SAFEBUF
#endif
#include "runtime/sharedRuntimeMath.hpp"
static const int init_jk[] = {2,3,4,6}; /* initial value for jk */
static const double PIo2[] = {
1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */
7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */
5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */
3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */
1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */
1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */
2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */
2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */
};
static const double
zeroB = 0.0,
one = 1.0,
two24B = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
twon24 = 5.96046447753906250000e-08; /* 0x3E700000, 0x00000000 */
static SAFEBUF int __kernel_rem_pio2(double *x, double *y, int e0, int nx, int prec, const int *ipio2) {
int jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih;
double z,fw,f[20],fq[20],q[20];
jk = init_jk[prec];
jp = jk;
jx = nx-1;
jv = (e0-3)/24; if(jv<0) jv=0;
q0 = e0-24*(jv+1);
j = jv-jx; m = jx+jk;
for(i=0;i<=m;i++,j++) f[i] = (j<0)? zeroB : (double) ipio2[j];
for (i=0;i<=jk;i++) {
for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j]; q[i] = fw;
}
jz = jk;
recompute:
for(i=0,j=jz,z=q[jz];j>0;i++,j--) {
fw = (double)((int)(twon24* z));
iq[i] = (int)(z-two24B*fw);
z = q[j-1]+fw;
}
z = scalbnA(z,q0); /* actual value of z */
z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */
n = (int) z;
z -= (double)n;
ih = 0;
if(q0>0) { /* need iq[jz-1] to determine n */
i = (iq[jz-1]>>(24-q0)); n += i;
iq[jz-1] -= i<<(24-q0);
ih = iq[jz-1]>>(23-q0);
}
else if(q0==0) ih = iq[jz-1]>>23;
else if(z>=0.5) ih=2;
if(ih>0) { /* q > 0.5 */
n += 1; carry = 0;
for(i=0;i<jz ;i++) { /* compute 1-q */
j = iq[i];
if(carry==0) {
if(j!=0) {
carry = 1; iq[i] = 0x1000000- j;
}
} else iq[i] = 0xffffff - j;
}
if(q0>0) { /* rare case: chance is 1 in 12 */
switch(q0) {
case 1:
iq[jz-1] &= 0x7fffff; break;
case 2:
iq[jz-1] &= 0x3fffff; break;
}
}
if(ih==2) {
z = one - z;
if(carry!=0) z -= scalbnA(one,q0);
}
}
if(z==zeroB) {
j = 0;
for (i=jz-1;i>=jk;i--) j |= iq[i];
if(j==0) { /* need recomputation */
for(k=1;iq[jk-k]==0;k++); /* k = no. of terms needed */
for(i=jz+1;i<=jz+k;i++) { /* add q[jz+1] to q[jz+k] */
f[jx+i] = (double) ipio2[jv+i];
for(j=0,fw=0.0;j<=jx;j++) fw += x[j]*f[jx+i-j];
q[i] = fw;
}
jz += k;
goto recompute;
}
}
if(z==0.0) {
jz -= 1; q0 -= 24;
while(iq[jz]==0) { jz--; q0-=24;}
} else { /* break z into 24-bit if neccessary */
z = scalbnA(z,-q0);
if(z>=two24B) {
fw = (double)((int)(twon24*z));
iq[jz] = (int)(z-two24B*fw);
jz += 1; q0 += 24;
iq[jz] = (int) fw;
} else iq[jz] = (int) z ;
}
fw = scalbnA(one,q0);
for(i=jz;i>=0;i--) {
q[i] = fw*(double)iq[i]; fw*=twon24;
}
for(i=jz;i>=0;i--) {
for(fw=0.0,k=0;k<=jp&&k<=jz-i;k++) fw += PIo2[k]*q[i+k];
fq[jz-i] = fw;
}
switch(prec) {
case 0:
fw = 0.0;
for (i=jz;i>=0;i--) fw += fq[i];
y[0] = (ih==0)? fw: -fw;
break;
case 1:
case 2:
fw = 0.0;
for (i=jz;i>=0;i--) fw += fq[i];
y[0] = (ih==0)? fw: -fw;
fw = fq[0]-fw;
for (i=1;i<=jz;i++) fw += fq[i];
y[1] = (ih==0)? fw: -fw;
break;
case 3: /* painful */
for (i=jz;i>0;i--) {
fw = fq[i-1]+fq[i];
fq[i] += fq[i-1]-fw;
fq[i-1] = fw;
}
for (i=jz;i>1;i--) {
fw = fq[i-1]+fq[i];
fq[i] += fq[i-1]-fw;
fq[i-1] = fw;
}
for (fw=0.0,i=jz;i>=2;i--) fw += fq[i];
if(ih==0) {
y[0] = fq[0]; y[1] = fq[1]; y[2] = fw;
} else {
y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw;
}
}
return n&7;
}
static const int two_over_pi[] = {
0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62,
0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A,
0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129,
0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41,
0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8,
0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF,
0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5,
0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08,
0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3,
0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880,
0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B,
};
static const int npio2_hw[] = {
0x3FF921FB, 0x400921FB, 0x4012D97C, 0x401921FB, 0x401F6A7A, 0x4022D97C,
0x4025FDBB, 0x402921FB, 0x402C463A, 0x402F6A7A, 0x4031475C, 0x4032D97C,
0x40346B9C, 0x4035FDBB, 0x40378FDB, 0x403921FB, 0x403AB41B, 0x403C463A,
0x403DD85A, 0x403F6A7A, 0x40407E4C, 0x4041475C, 0x4042106C, 0x4042D97C,
0x4043A28C, 0x40446B9C, 0x404534AC, 0x4045FDBB, 0x4046C6CB, 0x40478FDB,
0x404858EB, 0x404921FB,
};
static const double
zeroA = 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
two24A = 1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */
pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */
pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */
pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */
pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */
pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */
pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */
static SAFEBUF int __ieee754_rem_pio2(double x, double *y) {
double z,w,t,r,fn;
double tx[3];
int e0,i,j,nx,n,ix,hx,i0;
i0 = ((*(int*)&two24A)>>30)^1; /* high word index */
hx = *(i0+(int*)&x); /* high word of x */
ix = hx&0x7fffffff;
if(ix<=0x3fe921fb) /* |x| ~<= pi/4 , no need for reduction */
{y[0] = x; y[1] = 0; return 0;}
if(ix<0x4002d97c) { /* |x| < 3pi/4, special case with n=+-1 */
if(hx>0) {
z = x - pio2_1;
if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */
y[0] = z - pio2_1t;
y[1] = (z-y[0])-pio2_1t;
} else { /* near pi/2, use 33+33+53 bit pi */
z -= pio2_2;
y[0] = z - pio2_2t;
y[1] = (z-y[0])-pio2_2t;
}
return 1;
} else { /* negative x */
z = x + pio2_1;
if(ix!=0x3ff921fb) { /* 33+53 bit pi is good enough */
y[0] = z + pio2_1t;
y[1] = (z-y[0])+pio2_1t;
} else { /* near pi/2, use 33+33+53 bit pi */
z += pio2_2;
y[0] = z + pio2_2t;
y[1] = (z-y[0])+pio2_2t;
}
return -1;
}
}
if(ix<=0x413921fb) { /* |x| ~<= 2^19*(pi/2), medium size */
t = fabsd(x);
n = (int) (t*invpio2+half);
fn = (double)n;
r = t-fn*pio2_1;
w = fn*pio2_1t; /* 1st round good to 85 bit */
if(n<32&&ix!=npio2_hw[n-1]) {
y[0] = r-w; /* quick check no cancellation */
} else {
j = ix>>20;
y[0] = r-w;
i = j-(((*(i0+(int*)&y[0]))>>20)&0x7ff);
if(i>16) { /* 2nd iteration needed, good to 118 */
t = r;
w = fn*pio2_2;
r = t-w;
w = fn*pio2_2t-((t-r)-w);
y[0] = r-w;
i = j-(((*(i0+(int*)&y[0]))>>20)&0x7ff);
if(i>49) { /* 3rd iteration need, 151 bits acc */
t = r; /* will cover all possible cases */
w = fn*pio2_3;
r = t-w;
w = fn*pio2_3t-((t-r)-w);
y[0] = r-w;
}
}
}
y[1] = (r-y[0])-w;
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
else return n;
}
if(ix>=0x7ff00000) { /* x is inf or NaN */
y[0]=y[1]=x-x; return 0;
}
e0 = (ix>>20)-1046; /* e0 = ilogb(z)-23; */
for(i=0;i<2;i++) {
tx[i] = (double)((int)(z));
z = (z-tx[i])*two24A;
}
tx[2] = z;
nx = 3;
while(tx[nx-1]==zeroA) nx--; /* skip zero term */
n = __kernel_rem_pio2(tx,y,e0,nx,2,two_over_pi);
if(hx<0) {y[0] = -y[0]; y[1] = -y[1]; return -n;}
return n;
}
static const double
S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */
S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */
S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */
S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */
S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */
S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */
static double __kernel_sin(double x, double y, int iy)
{
double z,r,v;
int ix;
ix = high(x)&0x7fffffff; /* high word of x */
if(ix<0x3e400000) /* |x| < 2**-27 */
{if((int)x==0) return x;} /* generate inexact */
z = x*x;
v = z*x;
r = S2+z*(S3+z*(S4+z*(S5+z*S6)));
if(iy==0) return x+v*(S1+z*r);
else return x-((z*(half*y-v*r)-y)-v*S1);
}
static const double
C1 = 4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */
C2 = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */
C3 = 2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */
C4 = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */
C5 = 2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */
C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */
static double __kernel_cos(double x, double y)
{
double a,h,z,r,qx=0;
int ix;
ix = high(x)&0x7fffffff; /* ix = |x|'s high word*/
if(ix<0x3e400000) { /* if x < 2**27 */
if(((int)x)==0) return one; /* generate inexact */
}
z = x*x;
r = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*C6)))));
if(ix < 0x3FD33333) /* if |x| < 0.3 */
return one - (0.5*z - (z*r - x*y));
else {
if(ix > 0x3fe90000) { /* x > 0.78125 */
qx = 0.28125;
} else {
set_high(&qx, ix-0x00200000); /* x/4 */
set_low(&qx, 0);
}
h = 0.5*z-qx;
a = one-qx;
return a - (h - (z*r-x*y));
}
}
static const double
pio4 = 7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */
pio4lo= 3.06161699786838301793e-17, /* 0x3C81A626, 0x33145C07 */
T[] = {
3.33333333333334091986e-01, /* 0x3FD55555, 0x55555563 */
1.33333333333201242699e-01, /* 0x3FC11111, 0x1110FE7A */
5.39682539762260521377e-02, /* 0x3FABA1BA, 0x1BB341FE */
2.18694882948595424599e-02, /* 0x3F9664F4, 0x8406D637 */
8.86323982359930005737e-03, /* 0x3F8226E3, 0xE96E8493 */
3.59207910759131235356e-03, /* 0x3F6D6D22, 0xC9560328 */
1.45620945432529025516e-03, /* 0x3F57DBC8, 0xFEE08315 */
5.88041240820264096874e-04, /* 0x3F4344D8, 0xF2F26501 */
2.46463134818469906812e-04, /* 0x3F3026F7, 0x1A8D1068 */
7.81794442939557092300e-05, /* 0x3F147E88, 0xA03792A6 */
7.14072491382608190305e-05, /* 0x3F12B80F, 0x32F0A7E9 */
-1.85586374855275456654e-05, /* 0xBEF375CB, 0xDB605373 */
2.59073051863633712884e-05, /* 0x3EFB2A70, 0x74BF7AD4 */
};
static double __kernel_tan(double x, double y, int iy)
{
double z,r,v,w,s;
int ix,hx;
hx = high(x); /* high word of x */
ix = hx&0x7fffffff; /* high word of |x| */
if(ix<0x3e300000) { /* x < 2**-28 */
if((int)x==0) { /* generate inexact */
if (((ix | low(x)) | (iy + 1)) == 0)
return one / fabsd(x);
else {
if (iy == 1)
return x;
else { /* compute -1 / (x+y) carefully */
double a, t;
z = w = x + y;
set_low(&z, 0);
v = y - (z - x);
t = a = -one / w;
set_low(&t, 0);
s = one + t * z;
return t + a * (s + t * v);
}
}
}
}
if(ix>=0x3FE59428) { /* |x|>=0.6744 */
if(hx<0) {x = -x; y = -y;}
z = pio4-x;
w = pio4lo-y;
x = z+w; y = 0.0;
}
z = x*x;
w = z*z;
r = T[1]+w*(T[3]+w*(T[5]+w*(T[7]+w*(T[9]+w*T[11]))));
v = z*(T[2]+w*(T[4]+w*(T[6]+w*(T[8]+w*(T[10]+w*T[12])))));
s = z*x;
r = y + z*(s*(r+v)+y);
r += T[0]*s;
w = x+r;
if(ix>=0x3FE59428) {
v = (double)iy;
return (double)(1-((hx>>30)&2))*(v-2.0*(x-(w*w/(w+v)-r)));
}
if(iy==1) return w;
else { /* if allow error up to 2 ulp,
simply return -1.0/(x+r) here */
double a,t;
z = w;
set_low(&z, 0);
v = r-(z - x); /* z+v = r+x */
t = a = -1.0/w; /* a = -1.0/w */
set_low(&t, 0);
s = 1.0+t*z;
return t+a*(s+t*v);
}
}
JRT_LEAF(jdouble, SharedRuntime::dsin(jdouble x))
double y[2],z=0.0;
int n, ix;
ix = high(x);
ix &= 0x7fffffff;
if(ix <= 0x3fe921fb) return __kernel_sin(x,z,0);
else if (ix>=0x7ff00000) return x-x;
else {
n = __ieee754_rem_pio2(x,y);
switch(n&3) {
case 0: return __kernel_sin(y[0],y[1],1);
case 1: return __kernel_cos(y[0],y[1]);
case 2: return -__kernel_sin(y[0],y[1],1);
default:
return -__kernel_cos(y[0],y[1]);
}
}
JRT_END
JRT_LEAF(jdouble, SharedRuntime::dcos(jdouble x))
double y[2],z=0.0;
int n, ix;
ix = high(x);
ix &= 0x7fffffff;
if(ix <= 0x3fe921fb) return __kernel_cos(x,z);
else if (ix>=0x7ff00000) return x-x;
else {
n = __ieee754_rem_pio2(x,y);
switch(n&3) {
case 0: return __kernel_cos(y[0],y[1]);
case 1: return -__kernel_sin(y[0],y[1],1);
case 2: return -__kernel_cos(y[0],y[1]);
default:
return __kernel_sin(y[0],y[1],1);
}
}
JRT_END
JRT_LEAF(jdouble, SharedRuntime::dtan(jdouble x))
double y[2],z=0.0;
int n, ix;
ix = high(x);
ix &= 0x7fffffff;
if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1);
else if (ix>=0x7ff00000) return x-x; /* NaN */
else {
n = __ieee754_rem_pio2(x,y);
return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /* 1 -- n even
-1 -- n odd */
}
JRT_END
#ifdef WIN32
# pragma optimize ( "", on )
#endif
C:\hotspot-69087d08d473\src\share\vm/runtime/signature.cpp
#include "precompiled.hpp"
#include "classfile/symbolTable.hpp"
#include "classfile/systemDictionary.hpp"
#include "memory/oopFactory.hpp"
#include "oops/instanceKlass.hpp"
#include "oops/oop.inline.hpp"
#include "oops/symbol.hpp"
#include "oops/typeArrayKlass.hpp"
#include "runtime/signature.hpp"
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
SignatureIterator::SignatureIterator(Symbol* signature) {
_signature = signature;
_parameter_index = 0;
}
void SignatureIterator::expect(char c) {
if (_signature->byte_at(_index) != c) fatal(err_msg("expecting %c", c));
_index++;
}
void SignatureIterator::skip_optional_size() {
Symbol* sig = _signature;
char c = sig->byte_at(_index);
while ('0' <= c && c <= '9') c = sig->byte_at(++_index);
}
int SignatureIterator::parse_type() {
int size = -1;
switch(_signature->byte_at(_index)) {
case 'B': do_byte (); if (_parameter_index < 0 ) _return_type = T_BYTE;
_index++; size = T_BYTE_size ; break;
case 'C': do_char (); if (_parameter_index < 0 ) _return_type = T_CHAR;
_index++; size = T_CHAR_size ; break;
case 'D': do_double(); if (_parameter_index < 0 ) _return_type = T_DOUBLE;
_index++; size = T_DOUBLE_size ; break;
case 'F': do_float (); if (_parameter_index < 0 ) _return_type = T_FLOAT;
_index++; size = T_FLOAT_size ; break;
case 'I': do_int (); if (_parameter_index < 0 ) _return_type = T_INT;
_index++; size = T_INT_size ; break;
case 'J': do_long (); if (_parameter_index < 0 ) _return_type = T_LONG;
_index++; size = T_LONG_size ; break;
case 'S': do_short (); if (_parameter_index < 0 ) _return_type = T_SHORT;
_index++; size = T_SHORT_size ; break;
case 'Z': do_bool (); if (_parameter_index < 0 ) _return_type = T_BOOLEAN;
_index++; size = T_BOOLEAN_size; break;
case 'V': do_void (); if (_parameter_index < 0 ) _return_type = T_VOID;
_index++; size = T_VOID_size; ; break;
case 'L':
{ int begin = ++_index;
Symbol* sig = _signature;
while (sig->byte_at(_index++) != ';') ;
do_object(begin, _index);
}
if (_parameter_index < 0 ) _return_type = T_OBJECT;
size = T_OBJECT_size;
break;
case '[':
{ int begin = ++_index;
skip_optional_size();
Symbol* sig = _signature;
while (sig->byte_at(_index) == '[') {
_index++;
skip_optional_size();
}
if (sig->byte_at(_index) == 'L') {
while (sig->byte_at(_index++) != ';') ;
} else {
_index++;
}
do_array(begin, _index);
if (_parameter_index < 0 ) _return_type = T_ARRAY;
}
size = T_ARRAY_size;
break;
default:
ShouldNotReachHere();
break;
}
assert(size >= 0, "size must be set");
return size;
}
void SignatureIterator::check_signature_end() {
if (_index < _signature->utf8_length()) {
tty->print_cr("too many chars in signature");
_signature->print_value_on(tty);
tty->print_cr(" @ %d", _index);
}
}
void SignatureIterator::dispatch_field() {
_index = 0;
_parameter_index = 0;
parse_type();
check_signature_end();
}
void SignatureIterator::iterate_parameters() {
_index = 0;
_parameter_index = 0;
expect('(');
while (_signature->byte_at(_index) != ')') _parameter_index += parse_type();
expect(')');
_parameter_index = 0;
}
void SignatureIterator::iterate_parameters( uint64_t fingerprint ) {
uint64_t saved_fingerprint = fingerprint;
if ( fingerprint == UCONST64(-1) ) {
SignatureIterator::iterate_parameters();
return;
}
assert(fingerprint, "Fingerprint should not be 0");
_parameter_index = 0;
fingerprint = fingerprint >> (static_feature_size + result_feature_size);
while ( 1 ) {
switch ( fingerprint & parameter_feature_mask ) {
case bool_parm:
do_bool();
_parameter_index += T_BOOLEAN_size;
break;
case byte_parm:
do_byte();
_parameter_index += T_BYTE_size;
break;
case char_parm:
do_char();
_parameter_index += T_CHAR_size;
break;
case short_parm:
do_short();
_parameter_index += T_SHORT_size;
break;
case int_parm:
do_int();
_parameter_index += T_INT_size;
break;
case obj_parm:
do_object(0, 0);
_parameter_index += T_OBJECT_size;
break;
case long_parm:
do_long();
_parameter_index += T_LONG_size;
break;
case float_parm:
do_float();
_parameter_index += T_FLOAT_size;
break;
case double_parm:
do_double();
_parameter_index += T_DOUBLE_size;
break;
case done_parm:
return;
break;
default:
tty->print_cr("*** parameter is %d", fingerprint & parameter_feature_mask);
tty->print_cr("*** fingerprint is " PTR64_FORMAT, saved_fingerprint);
ShouldNotReachHere();
break;
}
fingerprint >>= parameter_feature_size;
}
_parameter_index = 0;
}
void SignatureIterator::iterate_returntype() {
_index = 0;
expect('(');
Symbol* sig = _signature;
while (sig->byte_at(_index) != ')') {
switch(sig->byte_at(_index)) {
case 'B':
case 'C':
case 'D':
case 'F':
case 'I':
case 'J':
case 'S':
case 'Z':
case 'V':
{
_index++;
}
break;
case 'L':
{
while (sig->byte_at(_index++) != ';') ;
}
break;
case '[':
{
int begin = ++_index;
skip_optional_size();
while (sig->byte_at(_index) == '[') {
_index++;
skip_optional_size();
}
if (sig->byte_at(_index) == 'L') {
while (sig->byte_at(_index++) != ';') ;
} else {
_index++;
}
}
break;
default:
ShouldNotReachHere();
break;
}
}
expect(')');
_parameter_index = -1;
parse_type();
check_signature_end();
_parameter_index = 0;
}
void SignatureIterator::iterate() {
_parameter_index = 0;
_index = 0;
expect('(');
while (_signature->byte_at(_index) != ')') _parameter_index += parse_type();
expect(')');
_parameter_index = -1;
parse_type();
check_signature_end();
_parameter_index = 0;
}
SignatureStream::SignatureStream(Symbol* signature, bool is_method) :
_signature(signature), _at_return_type(false) {
_begin = _end = (is_method ? 1 : 0); // skip first '(' in method signatures
_names = new GrowableArray<Symbol*>(10);
next();
}
SignatureStream::~SignatureStream() {
for (int i = 0; i < _names->length(); i++) {
_names->at(i)->decrement_refcount();
}
}
bool SignatureStream::is_done() const {
return _end > _signature->utf8_length();
}
void SignatureStream::next_non_primitive(int t) {
switch (t) {
case 'L': {
_type = T_OBJECT;
Symbol* sig = _signature;
while (sig->byte_at(_end++) != ';');
break;
}
case '[': {
_type = T_ARRAY;
Symbol* sig = _signature;
char c = sig->byte_at(_end);
while ('0' <= c && c <= '9') c = sig->byte_at(_end++);
while (sig->byte_at(_end) == '[') {
_end++;
c = sig->byte_at(_end);
while ('0' <= c && c <= '9') c = sig->byte_at(_end++);
}
switch(sig->byte_at(_end)) {
case 'B':
case 'C':
case 'D':
case 'F':
case 'I':
case 'J':
case 'S':
case 'Z':_end++; break;
default: {
while (sig->byte_at(_end++) != ';');
break;
}
}
break;
}
case ')': _end++; next(); _at_return_type = true; break;
default : ShouldNotReachHere();
}
}
bool SignatureStream::is_object() const {
return _type == T_OBJECT
|| _type == T_ARRAY;
}
bool SignatureStream::is_array() const {
return _type == T_ARRAY;
}
Symbol* SignatureStream::as_symbol(TRAPS) {
int begin = _begin;
int end = _end;
if ( _signature->byte_at(_begin) == 'L'
&& _signature->byte_at(_end-1) == ';') {
begin++;
end--;
}
Symbol* name = SymbolTable::new_symbol(_signature, begin, end, CHECK_NULL);
_names->push(name); // save new symbol for decrementing later
return name;
}
Klass* SignatureStream::as_klass(Handle class_loader, Handle protection_domain,
FailureMode failure_mode, TRAPS) {
if (!is_object()) return NULL;
Symbol* name = as_symbol(CHECK_NULL);
if (failure_mode == ReturnNull) {
return SystemDictionary::resolve_or_null(name, class_loader, protection_domain, THREAD);
} else {
bool throw_error = (failure_mode == NCDFError);
return SystemDictionary::resolve_or_fail(name, class_loader, protection_domain, throw_error, THREAD);
}
}
oop SignatureStream::as_java_mirror(Handle class_loader, Handle protection_domain,
FailureMode failure_mode, TRAPS) {
if (!is_object())
return Universe::java_mirror(type());
Klass* klass = as_klass(class_loader, protection_domain, failure_mode, CHECK_NULL);
if (klass == NULL) return NULL;
return klass->java_mirror();
}
Symbol* SignatureStream::as_symbol_or_null() {
ResourceMark rm;
int begin = _begin;
int end = _end;
if ( _signature->byte_at(_begin) == 'L'
&& _signature->byte_at(_end-1) == ';') {
begin++;
end--;
}
char* buffer = NEW_RESOURCE_ARRAY(char, end - begin);
for (int index = begin; index < end; index++) {
buffer[index - begin] = _signature->byte_at(index);
}
Symbol* result = SymbolTable::probe(buffer, end - begin);
return result;
}
int SignatureStream::reference_parameter_count() {
int args_count = 0;
for ( ; !at_return_type(); next()) {
if (is_object()) {
args_count++;
}
}
return args_count;
}
bool SignatureVerifier::is_valid_signature(Symbol* sig) {
const char* signature = (const char*)sig->bytes();
ssize_t len = sig->utf8_length();
if (signature == NULL || signature[0] == '\0' || len < 1) {
return false;
} else if (signature[0] == '(') {
return is_valid_method_signature(sig);
} else {
return is_valid_type_signature(sig);
}
}
bool SignatureVerifier::is_valid_method_signature(Symbol* sig) {
const char* method_sig = (const char*)sig->bytes();
ssize_t len = sig->utf8_length();
ssize_t index = 0;
if (method_sig != NULL && len > 1 && method_sig[index] == '(') {
++index;
while (index < len && method_sig[index] != ')') {
ssize_t res = is_valid_type(&method_sig[index], len - index);
if (res == -1) {
return false;
} else {
index += res;
}
}
if (index < len && method_sig[index] == ')') {
++index;
return (is_valid_type(&method_sig[index], len - index) == (len - index));
}
}
return false;
}
bool SignatureVerifier::is_valid_type_signature(Symbol* sig) {
const char* type_sig = (const char*)sig->bytes();
ssize_t len = sig->utf8_length();
return (type_sig != NULL && len >= 1 &&
(is_valid_type(type_sig, len) == len));
}
ssize_t SignatureVerifier::is_valid_type(const char* type, ssize_t limit) {
ssize_t index = 0;
while (index < limit && type[index] == '[') ++index;
if (index >= limit) {
return -1;
}
switch (type[index]) {
case 'B': case 'C': case 'D': case 'F': case 'I':
case 'J': case 'S': case 'Z': case 'V':
return index + 1;
case 'L':
for (index = index + 1; index < limit; ++index) {
char c = type[index];
if (c == ';') {
return index + 1;
}
if (invalid_name_char(c)) {
return -1;
}
}
default: ; // fall through
}
return -1;
}
bool SignatureVerifier::invalid_name_char(char c) {
switch (c) {
case '\0': case '.': case ';': case '[':
return true;
default:
return false;
}
}
C:\hotspot-69087d08d473\src\share\vm/runtime/signature.hpp
#ifndef SHARE_VM_RUNTIME_SIGNATURE_HPP
#define SHARE_VM_RUNTIME_SIGNATURE_HPP
#include "memory/allocation.hpp"
#include "oops/method.hpp"
#include "utilities/top.hpp"
class SignatureIterator: public ResourceObj {
protected:
Symbol* _signature; // the signature to iterate over
int _index; // the current character index (only valid during iteration)
int _parameter_index; // the current parameter index (0 outside iteration phase)
BasicType _return_type;
void expect(char c);
void skip_optional_size();
int parse_type(); // returns the parameter size in words (0 for void)
void check_signature_end();
public:
enum {
static_feature_size = 1,
result_feature_size = 4,
result_feature_mask = 0xF,
parameter_feature_size = 4,
parameter_feature_mask = 0xF,
bool_parm = 1,
byte_parm = 2,
char_parm = 3,
short_parm = 4,
int_parm = 5,
long_parm = 6,
float_parm = 7,
double_parm = 8,
obj_parm = 9,
done_parm = 10, // marker for end of parameters
max_size_of_parameters = (BitsPerLong-1 -
result_feature_size - parameter_feature_size -
static_feature_size) / parameter_feature_size
};
SignatureIterator(Symbol* signature);
void dispatch_field(); // dispatches once for field signatures
void iterate_parameters(); // iterates over parameters only
void iterate_parameters( uint64_t fingerprint );
void iterate_returntype(); // iterates over returntype only
void iterate(); // iterates over whole signature
int parameter_index() const { return _parameter_index; }
bool is_return_type() const { return parameter_index() < 0; }
BasicType get_ret_type() const { return _return_type; }
virtual void do_bool () = 0;
virtual void do_char () = 0;
virtual void do_float () = 0;
virtual void do_double() = 0;
virtual void do_byte () = 0;
virtual void do_short () = 0;
virtual void do_int () = 0;
virtual void do_long () = 0;
virtual void do_void () = 0;
virtual void do_object(int begin, int end) = 0;
virtual void do_array (int begin, int end) = 0;
};
class SignatureTypeNames : public SignatureIterator {
protected:
virtual void type_name(const char* name) = 0;
void do_bool() { type_name("jboolean"); }
void do_char() { type_name("jchar" ); }
void do_float() { type_name("jfloat" ); }
void do_double() { type_name("jdouble" ); }
void do_byte() { type_name("jbyte" ); }
void do_short() { type_name("jshort" ); }
void do_int() { type_name("jint" ); }
void do_long() { type_name("jlong" ); }
void do_void() { type_name("void" ); }
void do_object(int begin, int end) { type_name("jobject" ); }
void do_array (int begin, int end) { type_name("jobject" ); }
public:
SignatureTypeNames(Symbol* signature) : SignatureIterator(signature) {}
};
class SignatureInfo: public SignatureIterator {
protected:
bool _has_iterated; // need this because iterate cannot be called in constructor (set is virtual!)
bool _has_iterated_return;
int _size;
void lazy_iterate_parameters() { if (!_has_iterated) { iterate_parameters(); _has_iterated = true; } }
void lazy_iterate_return() { if (!_has_iterated_return) { iterate_returntype(); _has_iterated_return = true; } }
virtual void set(int size, BasicType type) = 0;
void do_bool () { set(T_BOOLEAN_size, T_BOOLEAN); }
void do_char () { set(T_CHAR_size , T_CHAR ); }
void do_float () { set(T_FLOAT_size , T_FLOAT ); }
void do_double() { set(T_DOUBLE_size , T_DOUBLE ); }
void do_byte () { set(T_BYTE_size , T_BYTE ); }
void do_short () { set(T_SHORT_size , T_SHORT ); }
void do_int () { set(T_INT_size , T_INT ); }
void do_long () { set(T_LONG_size , T_LONG ); }
void do_void () { set(T_VOID_size , T_VOID ); }
void do_object(int begin, int end) { set(T_OBJECT_size , T_OBJECT ); }
void do_array (int begin, int end) { set(T_ARRAY_size , T_ARRAY ); }
public:
SignatureInfo(Symbol* signature) : SignatureIterator(signature) {
_has_iterated = _has_iterated_return = false;
_size = 0;
_return_type = T_ILLEGAL;
}
};
class ArgumentSizeComputer: public SignatureInfo {
private:
void set(int size, BasicType type) { _size += size; }
public:
ArgumentSizeComputer(Symbol* signature) : SignatureInfo(signature) {}
int size() { lazy_iterate_parameters(); return _size; }
};
class ArgumentCount: public SignatureInfo {
private:
void set(int size, BasicType type) { _size ++; }
public:
ArgumentCount(Symbol* signature) : SignatureInfo(signature) {}
int size() { lazy_iterate_parameters(); return _size; }
};
class ResultTypeFinder: public SignatureInfo {
private:
void set(int size, BasicType type) { _return_type = type; }
public:
BasicType type() { lazy_iterate_return(); return _return_type; }
ResultTypeFinder(Symbol* signature) : SignatureInfo(signature) {}
};
class Fingerprinter: public SignatureIterator {
private:
uint64_t _fingerprint;
int _shift_count;
methodHandle mh;
public:
void do_bool() { _fingerprint |= (((uint64_t)bool_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_char() { _fingerprint |= (((uint64_t)char_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_byte() { _fingerprint |= (((uint64_t)byte_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_short() { _fingerprint |= (((uint64_t)short_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_int() { _fingerprint |= (((uint64_t)int_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_long() { _fingerprint |= (((uint64_t)long_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_float() { _fingerprint |= (((uint64_t)float_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_double() { _fingerprint |= (((uint64_t)double_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_object(int begin, int end) { _fingerprint |= (((uint64_t)obj_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_array (int begin, int end) { _fingerprint |= (((uint64_t)obj_parm) << _shift_count); _shift_count += parameter_feature_size; }
void do_void() { ShouldNotReachHere(); }
Fingerprinter(methodHandle method) : SignatureIterator(method->signature()) {
mh = method;
_fingerprint = 0;
}
uint64_t fingerprint() {
if (mh->constMethod()->fingerprint() != CONST64(0)) {
return mh->constMethod()->fingerprint();
}
if (mh->size_of_parameters() > max_size_of_parameters ) {
_fingerprint = UCONST64(-1);
mh->constMethod()->set_fingerprint(_fingerprint);
return _fingerprint;
}
assert( (int)mh->result_type() <= (int)result_feature_mask, "bad result type");
_fingerprint = mh->result_type();
_fingerprint <<= static_feature_size;
if (mh->is_static()) _fingerprint |= 1;
_shift_count = result_feature_size + static_feature_size;
iterate_parameters();
_fingerprint |= ((uint64_t)done_parm) << _shift_count;// mark end of sig
mh->constMethod()->set_fingerprint(_fingerprint);
return _fingerprint;
}
};
class NativeSignatureIterator: public SignatureIterator {
private:
methodHandle _method;
int _offset; // The java stack offset
int _prepended; // number of prepended JNI parameters (1 JNIEnv, plus 1 mirror if static)
int _jni_offset; // the current parameter offset, starting with 0
void do_bool () { pass_int(); _jni_offset++; _offset++; }
void do_char () { pass_int(); _jni_offset++; _offset++; }
void do_float () { pass_float(); _jni_offset++; _offset++; }
#ifdef _LP64
void do_double() { pass_double(); _jni_offset++; _offset += 2; }
#else
void do_double() { pass_double(); _jni_offset += 2; _offset += 2; }
#endif
void do_byte () { pass_int(); _jni_offset++; _offset++; }
void do_short () { pass_int(); _jni_offset++; _offset++; }
void do_int () { pass_int(); _jni_offset++; _offset++; }
#ifdef _LP64
void do_long () { pass_long(); _jni_offset++; _offset += 2; }
#else
void do_long () { pass_long(); _jni_offset += 2; _offset += 2; }
#endif
void do_void () { ShouldNotReachHere(); }
void do_object(int begin, int end) { pass_object(); _jni_offset++; _offset++; }
void do_array (int begin, int end) { pass_object(); _jni_offset++; _offset++; }
public:
methodHandle method() const { return _method; }
int offset() const { return _offset; }
int jni_offset() const { return _jni_offset + _prepended; }
bool is_static() const { return method()->is_static(); }
virtual void pass_int() = 0;
virtual void pass_long() = 0;
virtual void pass_object() = 0;
virtual void pass_float() = 0;
#ifdef _LP64
virtual void pass_double() = 0;
#else
virtual void pass_double() { pass_long(); } // may be same as long
#endif
NativeSignatureIterator(methodHandle method) : SignatureIterator(method->signature()) {
_method = method;
_offset = 0;
_jni_offset = 0;
const int JNIEnv_words = 1;
const int mirror_words = 1;
_prepended = !is_static() ? JNIEnv_words : JNIEnv_words + mirror_words;
}
void iterate() { iterate(Fingerprinter(method()).fingerprint());
}
void iterate( uint64_t fingerprint ) {
if (!is_static()) {
pass_object(); _jni_offset++; _offset++;
}
SignatureIterator::iterate_parameters( fingerprint );
}
};
class SignatureStream : public StackObj {
private:
Symbol* _signature;
int _begin;
int _end;
BasicType _type;
bool _at_return_type;
GrowableArray<Symbol*>* _names; // symbols created while parsing signature
public:
bool at_return_type() const { return _at_return_type; }
bool is_done() const;
void next_non_primitive(int t);
void next() {
Symbol* sig = _signature;
int len = sig->utf8_length();
if (_end >= len) {
_end = len + 1;
return;
}
_begin = _end;
int t = sig->byte_at(_begin);
switch (t) {
case 'B': _type = T_BYTE; break;
case 'C': _type = T_CHAR; break;
case 'D': _type = T_DOUBLE; break;
case 'F': _type = T_FLOAT; break;
case 'I': _type = T_INT; break;
case 'J': _type = T_LONG; break;
case 'S': _type = T_SHORT; break;
case 'Z': _type = T_BOOLEAN; break;
case 'V': _type = T_VOID; break;
default : next_non_primitive(t);
return;
}
_end++;
}
SignatureStream(Symbol* signature, bool is_method = true);
~SignatureStream();
bool is_object() const; // True if this argument is an object
bool is_array() const; // True if this argument is an array
BasicType type() const { return _type; }
Symbol* as_symbol(TRAPS);
enum FailureMode { ReturnNull, CNFException, NCDFError };
Klass* as_klass(Handle class_loader, Handle protection_domain, FailureMode failure_mode, TRAPS);
oop as_java_mirror(Handle class_loader, Handle protection_domain, FailureMode failure_mode, TRAPS);
const jbyte* raw_bytes() { return _signature->bytes() + _begin; }
int raw_length() { return _end - _begin; }
Symbol* as_symbol_or_null();
int reference_parameter_count();
};
class SignatureVerifier : public StackObj {
public:
static bool is_valid_signature(Symbol* sig);
static bool is_valid_method_signature(Symbol* sig);
static bool is_valid_type_signature(Symbol* sig);
private:
static ssize_t is_valid_type(const char*, ssize_t);
static bool invalid_name_char(char);
};
#endif // SHARE_VM_RUNTIME_SIGNATURE_HPP
C:\hotspot-69087d08d473\src\share\vm/runtime/simpleThresholdPolicy.cpp
#include "precompiled.hpp"
#include "compiler/compileBroker.hpp"
#include "memory/resourceArea.hpp"
#include "runtime/arguments.hpp"
#include "runtime/simpleThresholdPolicy.hpp"
#include "runtime/simpleThresholdPolicy.inline.hpp"
#include "code/scopeDesc.hpp"
void SimpleThresholdPolicy::print_counters(const char* prefix, methodHandle mh) {
int invocation_count = mh->invocation_count();
int backedge_count = mh->backedge_count();
MethodData* mdh = mh->method_data();
int mdo_invocations = 0, mdo_backedges = 0;
int mdo_invocations_start = 0, mdo_backedges_start = 0;
if (mdh != NULL) {
mdo_invocations = mdh->invocation_count();
mdo_backedges = mdh->backedge_count();
mdo_invocations_start = mdh->invocation_count_start();
mdo_backedges_start = mdh->backedge_count_start();
}
tty->print(" %stotal=%d,%d %smdo=%d(%d),%d(%d)", prefix,
invocation_count, backedge_count, prefix,
mdo_invocations, mdo_invocations_start,
mdo_backedges, mdo_backedges_start);
tty->print(" %smax levels=%d,%d", prefix,
mh->highest_comp_level(), mh->highest_osr_comp_level());
}
void SimpleThresholdPolicy::print_event(EventType type, methodHandle mh, methodHandle imh,
int bci, CompLevel level) {
bool inlinee_event = mh() != imh();
ttyLocker tty_lock;
tty->print("%lf: [", os::elapsedTime());
switch(type) {
case CALL:
tty->print("call");
break;
case LOOP:
tty->print("loop");
break;
case COMPILE:
tty->print("compile");
break;
case REMOVE_FROM_QUEUE:
tty->print("remove-from-queue");
break;
case UPDATE_IN_QUEUE:
tty->print("update-in-queue");
break;
case REPROFILE:
tty->print("reprofile");
break;
case MAKE_NOT_ENTRANT:
tty->print("make-not-entrant");
break;
default:
tty->print("unknown");
}
tty->print(" level=%d ", level);
ResourceMark rm;
char *method_name = mh->name_and_sig_as_C_string();
tty->print("[%s", method_name);
if (inlinee_event) {
char *inlinee_name = imh->name_and_sig_as_C_string();
tty->print(" [%s]] ", inlinee_name);
}
else tty->print("] ");
tty->print("@%d queues=%d,%d", bci, CompileBroker::queue_size(CompLevel_full_profile),
CompileBroker::queue_size(CompLevel_full_optimization));
print_specific(type, mh, imh, bci, level);
if (type != COMPILE) {
print_counters("", mh);
if (inlinee_event) {
print_counters("inlinee ", imh);
}
tty->print(" compilable=");
bool need_comma = false;
if (!mh->is_not_compilable(CompLevel_full_profile)) {
tty->print("c1");
need_comma = true;
}
if (!mh->is_not_osr_compilable(CompLevel_full_profile)) {
if (need_comma) tty->print(",");
tty->print("c1-osr");
need_comma = true;
}
if (!mh->is_not_compilable(CompLevel_full_optimization)) {
if (need_comma) tty->print(",");
tty->print("c2");
need_comma = true;
}
if (!mh->is_not_osr_compilable(CompLevel_full_optimization)) {
if (need_comma) tty->print(",");
tty->print("c2-osr");
}
tty->print(" status=");
if (mh->queued_for_compilation()) {
tty->print("in-queue");
} else tty->print("idle");
}
tty->print_cr("]");
}
void SimpleThresholdPolicy::initialize() {
if (FLAG_IS_DEFAULT(CICompilerCount)) {
FLAG_SET_DEFAULT(CICompilerCount, 3);
}
int count = CICompilerCount;
if (CICompilerCountPerCPU) {
count = MAX2(log2_int(os::active_processor_count()), 1) * 3 / 2;
}
set_c1_count(MAX2(count / 3, 1));
set_c2_count(MAX2(count - c1_count(), 1));
FLAG_SET_ERGO(intx, CICompilerCount, c1_count() + c2_count());
}
ssssssss75
最新推荐文章于 2024-09-09 00:00:00 发布