[*] Repeat old source check patch hack: remove SerializedCodeSanityCheckResult::kSourceMismatch

[+] Expose codegen cpu featureset as an API

(Previous hack: 95d8a9fdcc)
(Last real aurora commit: 21824f3e)
This commit is contained in:
Reece Wilson 2023-01-24 23:38:44 +00:00
parent 9fb9e65111
commit 6bf47ddb53
8 changed files with 110 additions and 82 deletions

View File

@ -17,6 +17,79 @@
namespace v8 {
enum CpuFeature {
#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X64
SSE4_2,
SSE4_1,
SSSE3,
SSE3,
SAHF,
AVX,
AVX2,
FMA3,
BMI1,
BMI2,
LZCNT,
POPCNT,
INTEL_ATOM,
CETSS,
#elif V8_TARGET_ARCH_ARM
// - Standard configurations. The baseline is ARMv6+VFPv2.
ARMv7, // ARMv7-A + VFPv3-D32 + NEON
ARMv7_SUDIV, // ARMv7-A + VFPv4-D32 + NEON + SUDIV
ARMv8, // ARMv8-A (+ all of the above)
// ARM feature aliases (based on the standard configurations above).
VFPv3 = ARMv7,
NEON = ARMv7,
VFP32DREGS = ARMv7,
SUDIV = ARMv7_SUDIV,
#elif V8_TARGET_ARCH_ARM64
JSCVT,
#elif V8_TARGET_ARCH_MIPS64
FPU,
FP64FPU,
MIPSr1,
MIPSr2,
MIPSr6,
MIPS_SIMD, // MSA instructions
#elif V8_TARGET_ARCH_LOONG64
FPU,
#elif V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_PPC64
PPC_6_PLUS,
PPC_7_PLUS,
PPC_8_PLUS,
PPC_9_PLUS,
PPC_10_PLUS,
#elif V8_TARGET_ARCH_S390X
FPU,
DISTINCT_OPS,
GENERAL_INSTR_EXT,
FLOATING_POINT_EXT,
VECTOR_FACILITY,
VECTOR_ENHANCE_FACILITY_1,
VECTOR_ENHANCE_FACILITY_2,
MISC_INSTR_EXT2,
#elif V8_TARGET_ARCH_RISCV64
FPU,
FP64FPU,
RISCV_SIMD,
#elif V8_TARGET_ARCH_RISCV32
FPU,
FP64FPU,
RISCV_SIMD,
#endif
NUMBER_OF_CPU_FEATURES
};
class Array;
class Context;
class Data;

View File

@ -199,6 +199,10 @@ enum class MemoryPressureLevel { kNone, kModerate, kCritical };
*/
using StackState = cppgc::EmbedderStackState;
V8_EXPORT size_t GetCPUFeatureMask();
V8_EXPORT size_t GetCPUFeatureMaskRescan();
V8_EXPORT void SetCPUFeatureMask(size_t features);
/**
* Isolate represents an isolated instance of the V8 engine. V8 isolates have
* completely separate states. Objects from one isolate must not be used in

View File

@ -1128,6 +1128,20 @@ bool Data::IsFunctionTemplate() const {
bool Data::IsContext() const { return Utils::OpenHandle(this)->IsContext(); }
size_t GetCPUFeatureMask() {
return internal::CpuFeatures::SupportedFeatures();
}
size_t GetCPUFeatureMaskRescan() {
internal::CpuFeatures::initialized_ = 0;
internal::CpuFeatures::supported_ = 0;
return internal::CpuFeatures::SupportedFeatures();
}
void SetCPUFeatureMask(size_t features) {
internal::CpuFeatures::supported_ = features;
}
void Context::Enter() {
i::DisallowGarbageCollection no_gc;
i::Context env = *Utils::OpenHandle(this);
@ -2998,7 +3012,7 @@ MaybeLocal<Module> ScriptCompiler::CompileModule(
uint32_t ScriptCompiler::CachedDataVersionTag() {
return static_cast<uint32_t>(base::hash_combine(
internal::Version::Hash(), internal::FlagList::Hash(),
static_cast<uint32_t>(internal::CpuFeatures::SupportedFeatures())));
static_cast<uint32_t>(0)));
}
ScriptCompiler::CachedData* ScriptCompiler::CreateCodeCache(

View File

@ -3457,6 +3457,8 @@ MaybeHandle<SharedFunctionInfo> GetSharedFunctionInfoForScriptImpl(
MaybeHandle<SharedFunctionInfo> maybe_result;
MaybeHandle<Script> maybe_script;
IsCompiledScope is_compiled_scope;
i::Handle<i::String> sourceName = source;
if (use_compilation_cache) {
bool can_consume_code_cache =
compile_options == ScriptCompiler::kConsumeCodeCache;
@ -3512,7 +3514,8 @@ MaybeHandle<SharedFunctionInfo> GetSharedFunctionInfoForScriptImpl(
Handle<SharedFunctionInfo> result;
if (maybe_result.ToHandle(&result)) {
is_compiled_scope = result->is_compiled_scope(isolate);
if (is_compiled_scope.is_compiled()) {
if (is_compiled_scope.is_compiled() && (sourceName->length() != 0)) {
consuming_code_cache_succeeded = true;
// Promote to per-isolate compilation cache.
compilation_cache->PutScript(source, language_mode, result);
@ -3556,7 +3559,8 @@ MaybeHandle<SharedFunctionInfo> GetSharedFunctionInfoForScriptImpl(
// Add the result to the isolate cache.
Handle<SharedFunctionInfo> result;
if (use_compilation_cache && maybe_result.ToHandle(&result)) {
if (use_compilation_cache && maybe_result.ToHandle(&result) &&
(sourceName->length() != 0)) {
DCHECK(is_compiled_scope.is_compiled());
compilation_cache->PutScript(source, language_mode, result);
} else if (maybe_result.is_null() && natives != EXTENSION_CODE) {

View File

@ -12,78 +12,6 @@ namespace v8 {
namespace internal {
// CPU feature flags.
enum CpuFeature {
#if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X64
SSE4_2,
SSE4_1,
SSSE3,
SSE3,
SAHF,
AVX,
AVX2,
FMA3,
BMI1,
BMI2,
LZCNT,
POPCNT,
INTEL_ATOM,
CETSS,
#elif V8_TARGET_ARCH_ARM
// - Standard configurations. The baseline is ARMv6+VFPv2.
ARMv7, // ARMv7-A + VFPv3-D32 + NEON
ARMv7_SUDIV, // ARMv7-A + VFPv4-D32 + NEON + SUDIV
ARMv8, // ARMv8-A (+ all of the above)
// ARM feature aliases (based on the standard configurations above).
VFPv3 = ARMv7,
NEON = ARMv7,
VFP32DREGS = ARMv7,
SUDIV = ARMv7_SUDIV,
#elif V8_TARGET_ARCH_ARM64
JSCVT,
#elif V8_TARGET_ARCH_MIPS64
FPU,
FP64FPU,
MIPSr1,
MIPSr2,
MIPSr6,
MIPS_SIMD, // MSA instructions
#elif V8_TARGET_ARCH_LOONG64
FPU,
#elif V8_TARGET_ARCH_PPC || V8_TARGET_ARCH_PPC64
PPC_6_PLUS,
PPC_7_PLUS,
PPC_8_PLUS,
PPC_9_PLUS,
PPC_10_PLUS,
#elif V8_TARGET_ARCH_S390X
FPU,
DISTINCT_OPS,
GENERAL_INSTR_EXT,
FLOATING_POINT_EXT,
VECTOR_FACILITY,
VECTOR_ENHANCE_FACILITY_1,
VECTOR_ENHANCE_FACILITY_2,
MISC_INSTR_EXT2,
#elif V8_TARGET_ARCH_RISCV64
FPU,
FP64FPU,
RISCV_SIMD,
#elif V8_TARGET_ARCH_RISCV32
FPU,
FP64FPU,
RISCV_SIMD,
#endif
NUMBER_OF_CPU_FEATURES
};
// CpuFeatures keeps track of which features are supported by the target CPU.
// Supported features must be enabled by a CpuFeatureScope before use.
@ -94,7 +22,7 @@ enum CpuFeature {
// } else {
// // Generate alternative code.
// }
class V8_EXPORT_PRIVATE CpuFeatures : public AllStatic {
class V8_EXPORT CpuFeatures : public AllStatic {
public:
CpuFeatures(const CpuFeatures&) = delete;
CpuFeatures& operator=(const CpuFeatures&) = delete;
@ -135,6 +63,9 @@ class V8_EXPORT_PRIVATE CpuFeatures : public AllStatic {
static void PrintTarget();
static void PrintFeatures();
// dont care lol
static unsigned supported_;
static bool initialized_;
private:
friend void V8_EXPORT_PRIVATE FlushInstructionCache(void*, size_t);
friend class ExternalReference;
@ -144,10 +75,8 @@ class V8_EXPORT_PRIVATE CpuFeatures : public AllStatic {
// Platform-dependent implementation.
static void ProbeImpl(bool cross_compile);
static unsigned supported_;
static unsigned icache_line_size_;
static unsigned dcache_line_size_;
static bool initialized_;
// This variable is only used for certain archs to query SupportWasmSimd128()
// at runtime in builtins using an extern ref. Other callers should use
// CpuFeatures::SupportWasmSimd128().

View File

@ -1674,7 +1674,7 @@ DEFINE_INT(switch_table_min_cases, 6,
DEFINE_BOOL(trace, false, "trace javascript function calls")
// codegen.cc
DEFINE_BOOL(lazy, true, "use lazy compilation")
DEFINE_BOOL(lazy, false, "use lazy compilation")
DEFINE_BOOL(lazy_eval, true, "use lazy compilation during eval")
DEFINE_BOOL(lazy_streaming, true,
"use lazy compilation during streaming compilation")
@ -2341,7 +2341,7 @@ DEFINE_IMPLICATION(print_all_code, print_regexp_code)
// Predictable mode related flags.
//
DEFINE_BOOL(predictable, false, "enable predictable mode")
DEFINE_BOOL(predictable, true, "enable predictable mode")
DEFINE_NEG_IMPLICATION(predictable, memory_reducer)
// TODO(v8:11848): These flags were recursively implied via --single-threaded
// before. Audit them, and remove any unneeded implications.

View File

@ -1253,6 +1253,10 @@ Handle<String> JSFunction::ToString(Handle<JSFunction> function) {
int end_position = class_positions.end();
Handle<String> script_source(
String::cast(Script::cast(shared_info->script()).source()), isolate);
if (script_source->length() == 0) {
return isolate->factory()->NewStringFromUtf8(v8::base::VectorOf("Compiled JSFunction", 19))
.ToHandleChecked();
}
return isolate->factory()->NewSubString(script_source, start_position,
end_position);
}

View File

@ -662,7 +662,7 @@ SerializedCodeSanityCheckResult SerializedCodeData::SanityCheckJustSource(
uint32_t expected_source_hash) const {
uint32_t source_hash = GetHeaderValue(kSourceHashOffset);
if (source_hash != expected_source_hash) {
return SerializedCodeSanityCheckResult::kSourceMismatch;
//return SerializedCodeSanityCheckResult::kSourceMismatch;
}
return SerializedCodeSanityCheckResult::kSuccess;
}
@ -785,4 +785,4 @@ SerializedCodeData SerializedCodeData::FromPartiallySanityCheckedCachedData(
}
} // namespace internal
} // namespace v8
} // namespace v8