Commit 0c1d2780 authored by jgruber's avatar jgruber Committed by Commit Bot

[builtins] Add isolate-independence cctest

The test inspects each builtin's RelocInfo. It's isolate-independent, iff there
are no entries for embedded objects, runtime calls, external references (which
could point to addresses on the isolate), or code targets.

Bug: v8:6666
Change-Id: Ie32353db445a9e81e1c9a0a8f1b5ffe1566a0404
Reviewed-on: https://chromium-review.googlesource.com/888639
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50949}
parent 4f67f022
......@@ -145,6 +145,7 @@
'../test/cctest/test-identity-map.cc',
'../test/cctest/test-intl.cc',
'../test/cctest/test-inobject-slack-tracking.cc',
'../test/cctest/test-isolate-independent-builtins.cc',
'../test/cctest/test-liveedit.cc',
'../test/cctest/test-lockers.cc',
'../test/cctest/test-log.cc',
......
......@@ -479,7 +479,7 @@ class RelocInfo {
mode == WASM_CALL || mode == JS_TO_WASM_CALL;
}
static inline int ModeMask(Mode mode) { return 1 << mode; }
static constexpr int ModeMask(Mode mode) { return 1 << mode; }
// Accessors
byte* pc() const { return pc_; }
......
......@@ -286,6 +286,33 @@ bool Builtins::IsLazy(int index) {
UNREACHABLE();
}
// static
bool Builtins::IsIsolateIndependent(int index) {
DCHECK(IsBuiltinId(index));
// TODO(jgruber): Extend this list.
switch (index) {
case kContinueToCodeStubBuiltin:
case kContinueToCodeStubBuiltinWithResult:
case kContinueToJavaScriptBuiltin:
case kContinueToJavaScriptBuiltinWithResult:
#ifndef DEBUG
#if !V8_TARGET_ARCH_IA32
case kClassOf:
case kConstructFunction:
case kTypeof:
case kWeakMapLookupHashIndex:
#endif
case kLoadIC_StringLength:
case kLoadIC_StringWrapperLength:
case kOrderedHashTableHealIndex:
#endif
return true;
default:
return false;
}
UNREACHABLE();
}
// static
Builtins::Kind Builtins::KindOf(int index) {
DCHECK(IsBuiltinId(index));
......
......@@ -114,6 +114,10 @@ class Builtins {
// special cases such as CompileLazy and DeserializeLazy.
static bool IsLazy(int index);
// Helper methods used for testing isolate-independent builtins.
// TODO(jgruber,v8:6666): Remove once all builtins have been migrated.
static bool IsIsolateIndependent(int index);
bool is_initialized() const { return initialized_; }
// Used by SetupIsolateDelegate and Deserializer.
......
......@@ -180,6 +180,7 @@ v8_source_set("cctest_sources") {
"test-identity-map.cc",
"test-inobject-slack-tracking.cc",
"test-intl.cc",
"test-isolate-independent-builtins.cc",
"test-liveedit.cc",
"test-lockers.cc",
"test-log.cc",
......
// Copyright 2018 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 "test/cctest/cctest.h"
#include "src/assembler.h"
#include "src/handles-inl.h"
#include "src/isolate.h"
#include "src/snapshot/snapshot.h"
namespace v8 {
namespace internal {
namespace test_isolate_independent_builtins {
TEST(VerifyBuiltinsIsolateIndependence) {
Isolate* isolate = CcTest::i_isolate();
HandleScope handle_scope(isolate);
// Build a white-list of all isolate-independent RelocInfo entry kinds.
constexpr int all_real_modes_mask =
(1 << (RelocInfo::LAST_REAL_RELOC_MODE + 1)) - 1;
constexpr int mode_mask =
all_real_modes_mask & ~RelocInfo::ModeMask(RelocInfo::COMMENT) &
~RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE) &
~RelocInfo::ModeMask(RelocInfo::INTERNAL_REFERENCE_ENCODED) &
~RelocInfo::ModeMask(RelocInfo::CONST_POOL) &
~RelocInfo::ModeMask(RelocInfo::VENEER_POOL);
STATIC_ASSERT(RelocInfo::LAST_REAL_RELOC_MODE == RelocInfo::VENEER_POOL);
STATIC_ASSERT(RelocInfo::ModeMask(RelocInfo::COMMENT) ==
(1 << RelocInfo::COMMENT));
STATIC_ASSERT(
mode_mask ==
(RelocInfo::ModeMask(RelocInfo::CODE_TARGET) |
RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
RelocInfo::ModeMask(RelocInfo::WASM_CONTEXT_REFERENCE) |
RelocInfo::ModeMask(RelocInfo::WASM_FUNCTION_TABLE_SIZE_REFERENCE) |
RelocInfo::ModeMask(RelocInfo::WASM_GLOBAL_HANDLE) |
RelocInfo::ModeMask(RelocInfo::WASM_CALL) |
RelocInfo::ModeMask(RelocInfo::JS_TO_WASM_CALL) |
RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY) |
RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE)));
constexpr bool kVerbose = false;
bool found_mismatch = false;
for (int i = 0; i < Builtins::builtin_count; i++) {
Code* code = isolate->builtins()->builtin(i);
// Make sure the builtin is deserialized.
if (code->builtin_index() == Builtins::kDeserializeLazy &&
Builtins::IsLazy(i)) {
code = Snapshot::DeserializeBuiltin(isolate, i);
}
if (kVerbose) {
printf("%s %s\n", Builtins::KindNameOf(i), isolate->builtins()->name(i));
}
bool is_isolate_independent = true;
for (RelocIterator it(code, mode_mask); !it.done(); it.next()) {
is_isolate_independent = false;
#ifdef ENABLE_DISASSEMBLER
if (kVerbose) {
RelocInfo::Mode mode = it.rinfo()->rmode();
printf(" %s\n", RelocInfo::RelocModeName(mode));
}
#endif
}
const bool expected_result = Builtins::IsIsolateIndependent(i);
if (is_isolate_independent != expected_result) {
found_mismatch = true;
printf("%s %s expected: %d, is: %d\n", Builtins::KindNameOf(i),
isolate->builtins()->name(i), expected_result,
is_isolate_independent);
}
}
CHECK(!found_mismatch);
}
} // namespace test_isolate_independent_builtins
} // namespace internal
} // namespace v8
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment