ec06bb6ce5
This is a reland of d1b27019d3
Fixes include:
Adding missing file to bazel build
Forward-declaring classing before friend-classing them to fix win/gcc
Add missing v8-isolate.h include for vtune builds
Original change's description:
> [include] Split out v8.h
>
> This moves every single class/function out of include/v8.h into a
> separate header in include/, which v8.h then includes so that
> externally nothing appears to have changed.
>
> Every include of v8.h from inside v8 has been changed to a more
> fine-grained include.
>
> Previously inline functions defined at the bottom of v8.h would call
> private non-inline functions in the V8 class. Since that class is now
> in v8-initialization.h and is rarely included (as that would create
> dependency cycles), this is not possible and so those methods have been
> moved out of the V8 class into the namespace v8::api_internal.
>
> None of the previous files in include/ now #include v8.h, which means
> if embedders were relying on this transitive dependency then it will
> give compile failures.
>
> v8-inspector.h does depend on v8-scripts.h for the time being to ensure
> that Chrome continue to compile but that change will be reverted once
> those transitive #includes in chrome are changed to include it directly.
>
> Full design:
> https://docs.google.com/document/d/1rTD--I8hCAr-Rho1WTumZzFKaDpEp0IJ8ejZtk4nJdA/edit?usp=sharing
>
> Bug: v8:11965
> Change-Id: I53b84b29581632710edc80eb11f819c2097a2877
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3097448
> Reviewed-by: Yang Guo <yangguo@chromium.org>
> Reviewed-by: Camillo Bruni <cbruni@chromium.org>
> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
> Reviewed-by: Leszek Swirski <leszeks@chromium.org>
> Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
> Commit-Queue: Dan Elphick <delphick@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#76424}
Cq-Include-Trybots: luci.v8.try:v8_linux_vtunejit
Bug: v8:11965
Change-Id: I99f5d3a73bf8fe25b650adfaf9567dc4e44a09e6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3113629
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Simon Zünd <szuend@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76460}
128 lines
4.3 KiB
C++
128 lines
4.3 KiB
C++
// Copyright 2019 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "include/v8-external.h"
|
|
#include "include/v8-function.h"
|
|
#include "include/v8-isolate.h"
|
|
#include "include/v8-local-handle.h"
|
|
#include "include/v8-template.h"
|
|
#include "src/base/win32-headers.h"
|
|
#include "src/init/v8.h"
|
|
#include "test/cctest/cctest.h"
|
|
|
|
#if defined(V8_OS_WIN_X64)
|
|
#define CONTEXT_PC(context) (context.Rip)
|
|
#elif defined(V8_OS_WIN_ARM64)
|
|
#define CONTEXT_PC(context) (context.Pc)
|
|
#endif
|
|
|
|
#include <windows.h>
|
|
|
|
// This has to come after windows.h.
|
|
#include <versionhelpers.h> // For IsWindows8OrGreater().
|
|
|
|
class UnwindingWin64Callbacks {
|
|
public:
|
|
UnwindingWin64Callbacks() = default;
|
|
|
|
static void Getter(v8::Local<v8::String> name,
|
|
const v8::PropertyCallbackInfo<v8::Value>& info) {
|
|
// Expects to find at least 15 stack frames in the call stack.
|
|
// The stack walking should fail on stack frames for builtin functions if
|
|
// stack unwinding data has not been correctly registered.
|
|
int stack_frames = CountCallStackFrames(15);
|
|
CHECK_GE(stack_frames, 15);
|
|
}
|
|
static void Setter(v8::Local<v8::String> name, v8::Local<v8::Value> value,
|
|
const v8::PropertyCallbackInfo<void>& info) {}
|
|
|
|
private:
|
|
// Windows-specific code to walk the stack starting from the current
|
|
// instruction pointer.
|
|
static int CountCallStackFrames(int max_frames) {
|
|
CONTEXT context_record;
|
|
::RtlCaptureContext(&context_record);
|
|
|
|
int iframe = 0;
|
|
while (++iframe < max_frames) {
|
|
uint64_t image_base;
|
|
PRUNTIME_FUNCTION function_entry = ::RtlLookupFunctionEntry(
|
|
CONTEXT_PC(context_record), &image_base, nullptr);
|
|
if (!function_entry) break;
|
|
|
|
void* handler_data;
|
|
uint64_t establisher_frame;
|
|
::RtlVirtualUnwind(UNW_FLAG_NHANDLER, image_base,
|
|
CONTEXT_PC(context_record), function_entry,
|
|
&context_record, &handler_data, &establisher_frame,
|
|
NULL);
|
|
}
|
|
return iframe;
|
|
}
|
|
};
|
|
|
|
// Verifies that stack unwinding data has been correctly registered on Win64.
|
|
UNINITIALIZED_TEST(StackUnwindingWin64) {
|
|
#ifdef V8_WIN64_UNWINDING_INFO
|
|
|
|
static const char* unwinding_win64_test_source =
|
|
"function start(count) {\n"
|
|
" for (var i = 0; i < count; i++) {\n"
|
|
" var o = instance.foo;\n"
|
|
" instance.foo = o + 1;\n"
|
|
" }\n"
|
|
"};\n"
|
|
"%PrepareFunctionForOptimization(start);\n";
|
|
|
|
// This test may fail on Windows 7
|
|
if (!::IsWindows8OrGreater()) {
|
|
return;
|
|
}
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
i::FLAG_win64_unwinding_info = true;
|
|
|
|
v8::Isolate::CreateParams create_params;
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
|
isolate->Enter();
|
|
{
|
|
v8::HandleScope scope(isolate);
|
|
LocalContext env(isolate);
|
|
|
|
v8::Local<v8::FunctionTemplate> func_template =
|
|
v8::FunctionTemplate::New(isolate);
|
|
v8::Local<v8::ObjectTemplate> instance_template =
|
|
func_template->InstanceTemplate();
|
|
|
|
UnwindingWin64Callbacks accessors;
|
|
v8::Local<v8::External> data = v8::External::New(isolate, &accessors);
|
|
instance_template->SetAccessor(v8_str("foo"),
|
|
&UnwindingWin64Callbacks::Getter,
|
|
&UnwindingWin64Callbacks::Setter, data);
|
|
v8::Local<v8::Function> func =
|
|
func_template->GetFunction(env.local()).ToLocalChecked();
|
|
v8::Local<v8::Object> instance =
|
|
func->NewInstance(env.local()).ToLocalChecked();
|
|
env->Global()->Set(env.local(), v8_str("instance"), instance).FromJust();
|
|
|
|
CompileRun(unwinding_win64_test_source);
|
|
v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
|
|
env->Global()->Get(env.local(), v8_str("start")).ToLocalChecked());
|
|
|
|
CompileRun("start(1); %OptimizeFunctionOnNextCall(start);");
|
|
|
|
int32_t repeat_count = 100;
|
|
v8::Local<v8::Value> args[] = {v8::Integer::New(isolate, repeat_count)};
|
|
function->Call(env.local(), env.local()->Global(), arraysize(args), args)
|
|
.ToLocalChecked();
|
|
}
|
|
isolate->Exit();
|
|
isolate->Dispose();
|
|
|
|
#endif // V8_WIN64_UNWINDING_INFO
|
|
}
|
|
|
|
#undef CONTEXT_PC
|