/* * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
#ifndef AMD64 // We store the current thread in this wrapperthread location // and determine how far away this address is from the structured // exception pointer that FS:[0] points to. This get_thread // code can then get the thread pointer via FS. // // Warning: This routine must NEVER be inlined since we'd end up with // multiple offsets. // volatile Thread* wrapperthread = thread;
if (os::win32::get_thread_ptr_offset() == 0) { int thread_ptr_offset;
__asm {
lea eax, dword ptr wrapperthread;
sub eax, dword ptr FS:[0H];
mov thread_ptr_offset, eax
};
os::win32::set_thread_ptr_offset(thread_ptr_offset);
} #ifdef ASSERT // Verify that the offset hasn't changed since we initially captured // it. This might happen if we accidentally ended up with an // inlined version of this routine. else { int test_thread_ptr_offset;
__asm {
lea eax, dword ptr wrapperthread;
sub eax, dword ptr FS:[0H];
mov test_thread_ptr_offset, eax
};
assert(test_thread_ptr_offset == os::win32::get_thread_ptr_offset(), "thread pointer offset from SEH changed");
} #endif// ASSERT #endif// !AMD64
// This is the language specific handler for exceptions // originating from dynamically generated code. // We call the standard structured exception handler // We only expect Continued Execution since we cannot unwind // from generated code. LONG HandleExceptionFromCodeCache(
IN PEXCEPTION_RECORD ExceptionRecord,
IN ULONG64 EstablisherFrame,
IN OUT PCONTEXT ContextRecord,
IN OUT PDISPATCHER_CONTEXT DispatcherContext) {
EXCEPTION_POINTERS ep; LONG result;
// We better only get a CONTINUE_EXECUTION from our handler // since we don't have unwind information registered.
guarantee( result == EXCEPTION_CONTINUE_EXECUTION, "Unexpected result from topLevelExceptionFilter");
return(ExceptionContinueExecution);
}
// Structure containing the Windows Data Structures required // to register our Code Cache exception handler. // We put these in the CodeCache since the API requires // all addresses in these structures are relative to the Code // area registered with RtlAddFunctionTable. typedefstruct { char ExceptionHandlerInstr[16]; // jmp HandleExceptionFromCodeCache
RUNTIME_FUNCTION rt;
UNWIND_INFO_EH_ONLY unw;
} DynamicCodeData, *pDynamicCodeData;
#endif// AMD64 // // Register our CodeCache area with the OS so it will dispatch exceptions // to our topLevelExceptionFilter when we take an exception in our // dynamically generated code. // // Arguments: low and high are the address of the full reserved // codeCache area // bool os::win32::register_code_area(char *low, char *high) { #ifdef AMD64
// Create an Unwind Structure specifying no unwind info // other than an Exception Handler
punwind = &pDCD->unw;
punwind->Version = 1;
punwind->Flags = UNW_FLAG_EHANDLER;
punwind->SizeOfProlog = 0;
punwind->CountOfCodes = 0;
punwind->FrameRegister = 0;
punwind->FrameOffset = 0;
punwind->ExceptionHandler = (char *)(&(pDCD->ExceptionHandlerInstr[0])) -
(char*)low;
punwind->ExceptionData[0] = 0;
// This structure describes the covered dynamic code area. // Addresses are relative to the beginning on the code cache area
prt = &pDCD->rt;
prt->BeginAddress = 0;
prt->EndAddress = (ULONG)(high - low);
prt->UnwindData = ((char *)punwind - low);
guarantee(RtlAddFunctionTable(prt, 1, (ULONGLONG)low), "Failed to register Dynamic Code Exception Handler with RtlAddFunctionTable");
#endif// AMD64 returntrue;
}
#ifdef HAVE_PLATFORM_PRINT_NATIVE_STACK /* * Windows/x64 does not use stack frames the way expected by Java: * [1] in most cases, there is no frame pointer. All locals are addressed via RSP * [2] in rare cases, when alloca() is used, a frame pointer is used, but this may * not be RBP. * See http://msdn.microsoft.com/en-us/library/ew5tede7.aspx * * So it's not possible to print the native stack using the * while (...) {... fr = os::get_sender_for_C_frame(&fr); } * loop in vmError.cpp. We need to roll our own loop.
*/ bool os::win32::platform_print_native_stack(outputStream* st, constvoid* context, char *buf, int buf_size)
{
CONTEXT ctx; if (context != NULL) {
memcpy(&ctx, context, sizeof(ctx));
} else {
RtlCaptureContext(&ctx);
}
int count = 0;
address lastpc = 0; while (count++ < StackPrintLimit) {
intptr_t* sp = (intptr_t*)stk.AddrStack.Offset;
intptr_t* fp = (intptr_t*)stk.AddrFrame.Offset; // NOT necessarily the same as ctx.Rbp!
address pc = (address)stk.AddrPC.Offset;
if (pc != NULL) { if (count == 2 && lastpc == pc) { // Skip it -- StackWalk64() may return the same PC // (but different SP) on the first try.
} else { // Don't try to create a frame(sp, fp, pc) -- on WinX64, stk.AddrFrame // may not contain what Java expects, and may cause the frame() constructor // to crash. Let's just print out the symbolic address.
frame::print_C_frame(st, buf, buf_size, pc); // print source file and line, if available char buf[128]; int line_no; if (SymbolEngine::get_source_info(pc, buf, sizeof(buf), &line_no)) {
st->print(" (%s:%d)", buf, line_no);
}
st->cr();
}
lastpc = pc;
}
PVOID p = WindowsDbgHelp::symFunctionTableAccess64(GetCurrentProcess(), stk.AddrPC.Offset); if (!p) { // StackWalk64() can't handle this PC. Calling StackWalk64 again may cause crash. break;
}
if (uc != NULL) {
epc = (address)uc->REG_PC; if (ret_sp) *ret_sp = (intptr_t*)uc->REG_SP; if (ret_fp) *ret_fp = (intptr_t*)uc->REG_FP;
} else {
epc = NULL; if (ret_sp) *ret_sp = (intptr_t *)NULL; if (ret_fp) *ret_fp = (intptr_t *)NULL;
}
return epc;
}
frame os::fetch_frame_from_context(constvoid* ucVoid) {
intptr_t* sp;
intptr_t* fp;
address epc = fetch_frame_from_context(ucVoid, &sp, &fp); if (!is_readable_pointer(epc)) { // Try to recover from calling into bad memory // Assume new frame has not been set up, the same as // compiled frame stack bang return frame(sp + 1, fp, (address)*sp);
} return frame(sp, fp, epc);
}
#ifndef AMD64 // Ignore "C4172: returning address of local variable or temporary" on 32bit
PRAGMA_DIAG_PUSH
PRAGMA_DISABLE_MSVC_WARNING(4172) // Returns an estimate of the current stack pointer. Result must be guaranteed // to point into the calling threads stack, and be no lower than the current // stack pointer.
address os::current_stack_pointer() { int dummy;
address sp = (address)&dummy; return sp;
}
PRAGMA_DIAG_POP #else // Returns the current stack pointer. Accurate value needed for // os::verify_stack_alignment().
address os::current_stack_pointer() { typedef address get_sp_func();
get_sp_func* func = CAST_TO_FN_PTR(get_sp_func*,
StubRoutines::x86::get_previous_sp_entry()); return (*func)();
} #endif
bool os::win32::get_frame_at_stack_banging_point(JavaThread* thread, struct _EXCEPTION_POINTERS* exceptionInfo, address pc, frame* fr) {
PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord;
address addr = (address) exceptionRecord->ExceptionInformation[1]; if (Interpreter::contains(pc)) {
*fr = os::fetch_frame_from_context((void*)exceptionInfo->ContextRecord); if (!fr->is_first_java_frame()) { // get_frame_at_stack_banging_point() is only called when we // have well defined stacks so java_sender() calls do not need // to assert safe_for_sender() first.
*fr = fr->java_sender();
}
} else { // more complex code with compiled code
assert(!Interpreter::contains(pc), "Interpreted methods should have been handled above");
CodeBlob* cb = CodeCache::find_blob(pc); if (cb == NULL || !cb->is_nmethod() || cb->is_frame_complete_at(pc)) { // Not sure where the pc points to, fallback to default // stack overflow handling returnfalse;
} else { // in compiled code, the stack banging is performed just after the return pc // has been pushed on the stack
intptr_t* fp = (intptr_t*)exceptionInfo->ContextRecord->REG_FP;
intptr_t* sp = (intptr_t*)exceptionInfo->ContextRecord->REG_SP;
*fr = frame(sp + 1, fp, (address)*sp); if (!fr->is_java_frame()) { // See java_sender() comment above.
*fr = fr->java_sender();
}
}
}
assert(fr->is_java_frame(), "Safety check"); returntrue;
}
// VC++ does not save frame pointer on stack in optimized build. It // can be turned off by /Oy-. If we really want to walk C frames, // we can use the StackWalk() API.
frame os::get_sender_for_C_frame(frame* fr) {
ShouldNotReachHere(); return frame();
}
frame os::current_frame() { return frame(); // cannot walk Windows frames this way. See os::get_native_stack // and os::platform_print_native_stack
}
// Note: it may be unsafe to inspect memory near pc. For example, pc may // point to garbage if entry point in an nmethod is corrupted. Leave // this at the end, and hope for the best.
address pc = os::fetch_frame_from_context(uc).pc();
print_instructions(st, pc, sizeof(char));
st->cr();
}
extern"C"int SpinPause () { #ifdef AMD64 return 0 ; #else // pause == rep:nop // On systems that don't support pause a rep:nop // is executed as a nop. The rep: prefix is ignored.
_asm {
pause ;
}; return 1 ; #endif// AMD64
}
juint os::cpu_microcode_revision() {
juint result = 0;
BYTE data[8] = {0};
HKEY key;
DWORD status = RegOpenKey(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", &key); if (status == ERROR_SUCCESS) {
DWORD size = sizeof(data);
status = RegQueryValueEx(key, "Update Revision", NULL, NULL, data, &size); if (status == ERROR_SUCCESS) { if (size == 4) result = *((juint*)data); if (size == 8) result = *((juint*)data + 1); // upper 32-bits
}
RegCloseKey(key);
} return result;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.