From 2fe0f48d39f4fd61985857c9d8e4997f5ca03582 Mon Sep 17 00:00:00 2001 From: "svenpanne@chromium.org" Date: Mon, 28 Apr 2014 08:18:38 +0000 Subject: [PATCH] Simplified CPU/CpuFeatures a bit. This is a necessary intermediate step to disentangle the startup. In the long run CPU and CpuFeatures should probably be merged, and Serializer::enabled usage should be radically reduced, but we're not there yet. BUG=359977 LOG=y R=bmeurer@chromium.org Review URL: https://codereview.chromium.org/258993002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21001 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/assembler-arm.cc | 19 ------------------- src/arm/assembler-arm.h | 12 +++--------- src/arm/cpu-arm.cc | 10 ---------- src/arm64/cpu-arm64.cc | 12 +----------- src/arm64/cpu-arm64.h | 4 +++- src/cpu.h | 5 ----- src/flags.cc | 9 +++++++-- src/flags.h | 9 ++++++++- src/ia32/assembler-ia32.cc | 4 ++-- src/ia32/assembler-ia32.h | 4 +++- src/ia32/cpu-ia32.cc | 10 ---------- src/isolate.cc | 2 +- src/mips/assembler-mips.cc | 17 ----------------- src/mips/assembler-mips.h | 9 +++------ src/mips/cpu-mips.cc | 10 ---------- src/mksnapshot.cc | 8 +------- src/v8.cc | 2 +- src/x64/assembler-x64.cc | 4 ++-- src/x64/assembler-x64.h | 4 +++- src/x64/cpu-x64.cc | 10 ---------- 20 files changed, 38 insertions(+), 126 deletions(-) diff --git a/src/arm/assembler-arm.cc b/src/arm/assembler-arm.cc index 5c1c311..7767fd2 100644 --- a/src/arm/assembler-arm.cc +++ b/src/arm/assembler-arm.cc @@ -48,7 +48,6 @@ namespace internal { #ifdef DEBUG bool CpuFeatures::initialized_ = false; #endif -bool CpuFeatures::hint_creating_snapshot_ = false; unsigned CpuFeatures::supported_ = 0; unsigned CpuFeatures::found_by_runtime_probing_only_ = 0; unsigned CpuFeatures::cross_compile_ = 0; @@ -101,22 +100,6 @@ const char* DwVfpRegister::AllocationIndexToString(int index) { } -void CpuFeatures::SetHintCreatingSnapshot() { - hint_creating_snapshot_ = true; -} - - -void CpuFeatures::ProbeWithoutIsolate() { - Probe(hint_creating_snapshot_); -} - - -void CpuFeatures::Probe() { - // The Serializer can only be queried after isolate initialization. - Probe(Serializer::enabled()); -} - - void CpuFeatures::Probe(bool serializer_enabled) { uint64_t standard_features = static_cast( OS::CpuFeaturesImpliedByPlatform()) | CpuFeaturesImpliedByCompiler(); @@ -133,8 +116,6 @@ void CpuFeatures::Probe(bool serializer_enabled) { if (serializer_enabled) { // No probing for features if we might serialize (generate snapshot). - printf(" "); - PrintFeatures(); return; } diff --git a/src/arm/assembler-arm.h b/src/arm/assembler-arm.h index f64cc5c..df22a20 100644 --- a/src/arm/assembler-arm.h +++ b/src/arm/assembler-arm.h @@ -56,12 +56,7 @@ class CpuFeatures : public AllStatic { public: // Detect features of the target CPU. Set safe defaults if the serializer // is enabled (snapshots must be portable). - static void Probe(); - - // A special case for printing target and features, which we want to do - // before initializing the isolate - static void SetHintCreatingSnapshot(); - static void ProbeWithoutIsolate(); + static void Probe(bool serializer_enabled); // Display target use when compiling. static void PrintTarget(); @@ -98,10 +93,9 @@ class CpuFeatures : public AllStatic { (cross_compile_ & mask) == mask; } - private: - static void Probe(bool serializer_enabled); - static bool hint_creating_snapshot_; + static bool SupportsCrankshaft() { return CpuFeatures::IsSupported(VFP3); } + private: static bool Check(CpuFeature f, unsigned set) { return (set & flag2set(f)) != 0; } diff --git a/src/arm/cpu-arm.cc b/src/arm/cpu-arm.cc index 20c6a5d..198a244 100644 --- a/src/arm/cpu-arm.cc +++ b/src/arm/cpu-arm.cc @@ -46,16 +46,6 @@ namespace v8 { namespace internal { -void CPU::SetUp() { - CpuFeatures::Probe(); -} - - -bool CPU::SupportsCrankshaft() { - return CpuFeatures::IsSupported(VFP3); -} - - void CPU::FlushICache(void* start, size_t size) { // Nothing to do flushing no instructions. if (size == 0) { diff --git a/src/arm64/cpu-arm64.cc b/src/arm64/cpu-arm64.cc index b8899ad..bdc4a03 100644 --- a/src/arm64/cpu-arm64.cc +++ b/src/arm64/cpu-arm64.cc @@ -49,16 +49,6 @@ unsigned CpuFeatures::dcache_line_size_ = 1; unsigned CpuFeatures::icache_line_size_ = 1; -void CPU::SetUp() { - CpuFeatures::Probe(); -} - - -bool CPU::SupportsCrankshaft() { - return true; -} - - void CPU::FlushICache(void* address, size_t length) { if (length == 0) { return; @@ -139,7 +129,7 @@ void CPU::FlushICache(void* address, size_t length) { } -void CpuFeatures::Probe() { +void CpuFeatures::Probe(bool serializer_enabled) { // Compute I and D cache line size. The cache type register holds // information about the caches. uint32_t cache_type_register = GetCacheType(); diff --git a/src/arm64/cpu-arm64.h b/src/arm64/cpu-arm64.h index ddec72d..009cead 100644 --- a/src/arm64/cpu-arm64.h +++ b/src/arm64/cpu-arm64.h @@ -42,7 +42,7 @@ class CpuFeatures : public AllStatic { public: // Detect features of the target CPU. Set safe defaults if the serializer // is enabled (snapshots must be portable). - static void Probe(); + static void Probe(bool serializer_enabled); // Check whether a feature is supported by the target CPU. static bool IsSupported(CpuFeature f) { @@ -81,6 +81,8 @@ class CpuFeatures : public AllStatic { return true; } + static bool SupportsCrankshaft() { return true; } + private: // Return the content of the cache type register. static uint32_t GetCacheType(); diff --git a/src/cpu.h b/src/cpu.h index b2e9f7d..b1ca746 100644 --- a/src/cpu.h +++ b/src/cpu.h @@ -102,11 +102,6 @@ class CPU V8_FINAL BASE_EMBEDDED { // Returns the number of processors online. static int NumberOfProcessorsOnline(); - // Initializes the cpu architecture support. Called once at VM startup. - static void SetUp(); - - static bool SupportsCrankshaft(); - // Flush instruction cache. static void FlushICache(void* start, size_t size); diff --git a/src/flags.cc b/src/flags.cc index 7feb51f..e241f55 100644 --- a/src/flags.cc +++ b/src/flags.cc @@ -360,10 +360,15 @@ static Flag* FindFlag(const char* name) { } +bool FlagList::serializer_enabled_ = false; + + // static int FlagList::SetFlagsFromCommandLine(int* argc, char** argv, - bool remove_flags) { + bool remove_flags, + bool serializer_enabled) { + serializer_enabled_ = serializer_enabled; int return_code = 0; // parse arguments for (int i = 1; i < *argc;) { @@ -545,7 +550,7 @@ void FlagList::ResetAllFlags() { void FlagList::PrintHelp() { #if V8_TARGET_ARCH_ARM CpuFeatures::PrintTarget(); - CpuFeatures::ProbeWithoutIsolate(); + CpuFeatures::Probe(serializer_enabled_); CpuFeatures::PrintFeatures(); #endif // V8_TARGET_ARCH_ARM diff --git a/src/flags.h b/src/flags.h index fe182e5..70376b0 100644 --- a/src/flags.h +++ b/src/flags.h @@ -63,7 +63,10 @@ class FlagList { // --flag=value (non-bool flags only, no spaces around '=') // --flag value (non-bool flags only) // -- (equivalent to --js_arguments, captures all remaining args) - static int SetFlagsFromCommandLine(int* argc, char** argv, bool remove_flags); + static int SetFlagsFromCommandLine(int* argc, + char** argv, + bool remove_flags, + bool serializer_enabled = false); // Set the flag values by parsing the string str. Splits string into argc // substrings argv[], each of which consisting of non-white-space chars, @@ -78,6 +81,10 @@ class FlagList { // Set flags as consequence of being implied by another flag. static void EnforceFlagImplications(); + + private: + // TODO(svenpanne) Remove this when Serializer/startup has been refactored. + static bool serializer_enabled_; }; } } // namespace v8::internal diff --git a/src/ia32/assembler-ia32.cc b/src/ia32/assembler-ia32.cc index 407f93e..8438e07 100644 --- a/src/ia32/assembler-ia32.cc +++ b/src/ia32/assembler-ia32.cc @@ -89,13 +89,13 @@ const char* IntelDoubleRegister::AllocationIndexToString(int index) { } -void CpuFeatures::Probe() { +void CpuFeatures::Probe(bool serializer_enabled) { ASSERT(!initialized_); ASSERT(supported_ == 0); #ifdef DEBUG initialized_ = true; #endif - if (Serializer::enabled()) { + if (serializer_enabled) { supported_ |= OS::CpuFeaturesImpliedByPlatform(); return; // No features if we might serialize. } diff --git a/src/ia32/assembler-ia32.h b/src/ia32/assembler-ia32.h index 2a8e454..30c13a3 100644 --- a/src/ia32/assembler-ia32.h +++ b/src/ia32/assembler-ia32.h @@ -530,7 +530,7 @@ class CpuFeatures : public AllStatic { public: // Detect features of the target CPU. Set safe defaults if the serializer // is enabled (snapshots must be portable). - static void Probe(); + static void Probe(bool serializer_enabled); // Check whether a feature is supported by the target CPU. static bool IsSupported(CpuFeature f) { @@ -564,6 +564,8 @@ class CpuFeatures : public AllStatic { (cross_compile_ & mask) == mask; } + static bool SupportsCrankshaft() { return IsSupported(SSE2); } + private: static bool Check(CpuFeature f, uint64_t set) { return (set & flag2set(f)) != 0; diff --git a/src/ia32/cpu-ia32.cc b/src/ia32/cpu-ia32.cc index 5fb04fc..3ea70f2 100644 --- a/src/ia32/cpu-ia32.cc +++ b/src/ia32/cpu-ia32.cc @@ -41,16 +41,6 @@ namespace v8 { namespace internal { -void CPU::SetUp() { - CpuFeatures::Probe(); -} - - -bool CPU::SupportsCrankshaft() { - return CpuFeatures::IsSupported(SSE2); -} - - void CPU::FlushICache(void* start, size_t size) { // No need to flush the instruction cache on Intel. On Intel instruction // cache flushing is only necessary when multiple cores running the same diff --git a/src/isolate.cc b/src/isolate.cc index 8f5b968..9071c02 100644 --- a/src/isolate.cc +++ b/src/isolate.cc @@ -1808,7 +1808,7 @@ bool Isolate::Init(Deserializer* des) { use_crankshaft_ = FLAG_crankshaft && !Serializer::enabled() - && CPU::SupportsCrankshaft(); + && CpuFeatures::SupportsCrankshaft(); if (function_entry_hook() != NULL) { // When function entry hooking is in effect, we have to create the code diff --git a/src/mips/assembler-mips.cc b/src/mips/assembler-mips.cc index f3a57f9..ccdc114 100644 --- a/src/mips/assembler-mips.cc +++ b/src/mips/assembler-mips.cc @@ -46,7 +46,6 @@ namespace internal { #ifdef DEBUG bool CpuFeatures::initialized_ = false; #endif -bool CpuFeatures::hint_creating_snapshot_ = false; unsigned CpuFeatures::supported_ = 0; unsigned CpuFeatures::found_by_runtime_probing_only_ = 0; unsigned CpuFeatures::cross_compile_ = 0; @@ -103,22 +102,6 @@ const char* DoubleRegister::AllocationIndexToString(int index) { } -void CpuFeatures::SetHintCreatingSnapshot() { - hint_creating_snapshot_ = true; -} - - -void CpuFeatures::ProbeWithoutIsolate() { - Probe(hint_creating_snapshot_); -} - - -void CpuFeatures::Probe() { - // The Serializer can only be queried after isolate initialization. - Probe(Serializer::enabled()); -} - - void CpuFeatures::Probe(bool serializer_enabled) { unsigned standard_features = (OS::CpuFeaturesImpliedByPlatform() | CpuFeaturesImpliedByCompiler()); diff --git a/src/mips/assembler-mips.h b/src/mips/assembler-mips.h index e4729b2..8c186c1 100644 --- a/src/mips/assembler-mips.h +++ b/src/mips/assembler-mips.h @@ -425,12 +425,10 @@ class CpuFeatures : public AllStatic { public: // Detect features of the target CPU. Set safe defaults if the serializer // is enabled (snapshots must be portable). - static void Probe(); + static void Probe(bool serializer_enabled); // A special case for printing target and features, which we want to do // before initializing the isolate - static void SetHintCreatingSnapshot(); - static void ProbeWithoutIsolate(); // Check whether a feature is supported by the target CPU. static bool IsSupported(CpuFeature f) { @@ -459,10 +457,9 @@ class CpuFeatures : public AllStatic { (cross_compile_ & mask) == mask; } - private: - static void Probe(bool serializer_enabled); - static bool hint_creating_snapshot_; + static bool SupportsCrankshaft() { return CpuFeatures::IsSupported(FPU); } + private: static bool Check(CpuFeature f, unsigned set) { return (set & flag2set(f)) != 0; } diff --git a/src/mips/cpu-mips.cc b/src/mips/cpu-mips.cc index 49d0b37..54026d1 100644 --- a/src/mips/cpu-mips.cc +++ b/src/mips/cpu-mips.cc @@ -47,16 +47,6 @@ namespace v8 { namespace internal { -void CPU::SetUp() { - CpuFeatures::Probe(); -} - - -bool CPU::SupportsCrankshaft() { - return CpuFeatures::IsSupported(FPU); -} - - void CPU::FlushICache(void* start, size_t size) { // Nothing to do, flushing no instructions. if (size == 0) { diff --git a/src/mksnapshot.cc b/src/mksnapshot.cc index 9f91b83..f3a652f 100644 --- a/src/mksnapshot.cc +++ b/src/mksnapshot.cc @@ -301,15 +301,9 @@ int main(int argc, char** argv) { // By default, log code create information in the snapshot. i::FLAG_log_code = true; -#if V8_TARGET_ARCH_ARM - // Printing flags on ARM requires knowing if we intend to enable - // the serializer or not. - v8::internal::CpuFeatures::SetHintCreatingSnapshot(); -#endif - // Print the usage if an error occurs when parsing the command line // flags or if the help flag is set. - int result = i::FlagList::SetFlagsFromCommandLine(&argc, argv, true); + int result = i::FlagList::SetFlagsFromCommandLine(&argc, argv, true, true); if (result > 0 || argc != 2 || i::FLAG_help) { ::printf("Usage: %s [flag] ... outfile\n", argv[0]); i::FlagList::PrintHelp(); diff --git a/src/v8.cc b/src/v8.cc index 70a4983..c1eedd4 100644 --- a/src/v8.cc +++ b/src/v8.cc @@ -144,7 +144,7 @@ void V8::InitializeOncePerProcessImpl() { platform_ = new DefaultPlatform; #endif Sampler::SetUp(); - CPU::SetUp(); + CpuFeatures::Probe(Serializer::enabled()); OS::PostSetUp(); ElementsAccessor::InitializeOncePerProcess(); LOperand::SetUpCaches(); diff --git a/src/x64/assembler-x64.cc b/src/x64/assembler-x64.cc index da2db62..359408a 100644 --- a/src/x64/assembler-x64.cc +++ b/src/x64/assembler-x64.cc @@ -52,13 +52,13 @@ ExternalReference ExternalReference::cpu_features() { } -void CpuFeatures::Probe() { +void CpuFeatures::Probe(bool serializer_enabled) { ASSERT(supported_ == CpuFeatures::kDefaultCpuFeatures); #ifdef DEBUG initialized_ = true; #endif supported_ = kDefaultCpuFeatures; - if (Serializer::enabled()) { + if (serializer_enabled) { supported_ |= OS::CpuFeaturesImpliedByPlatform(); return; // No features if we might serialize. } diff --git a/src/x64/assembler-x64.h b/src/x64/assembler-x64.h index 43475d1..702be58 100644 --- a/src/x64/assembler-x64.h +++ b/src/x64/assembler-x64.h @@ -450,7 +450,7 @@ class CpuFeatures : public AllStatic { public: // Detect features of the target CPU. Set safe defaults if the serializer // is enabled (snapshots must be portable). - static void Probe(); + static void Probe(bool serializer_enabled); // Check whether a feature is supported by the target CPU. static bool IsSupported(CpuFeature f) { @@ -484,6 +484,8 @@ class CpuFeatures : public AllStatic { (cross_compile_ & mask) == mask; } + static bool SupportsCrankshaft() { return true; } + private: static bool Check(CpuFeature f, uint64_t set) { return (set & flag2set(f)) != 0; diff --git a/src/x64/cpu-x64.cc b/src/x64/cpu-x64.cc index 4fa290a..7a4dd0c 100644 --- a/src/x64/cpu-x64.cc +++ b/src/x64/cpu-x64.cc @@ -41,16 +41,6 @@ namespace v8 { namespace internal { -void CPU::SetUp() { - CpuFeatures::Probe(); -} - - -bool CPU::SupportsCrankshaft() { - return true; // Yay! -} - - void CPU::FlushICache(void* start, size_t size) { // No need to flush the instruction cache on Intel. On Intel instruction // cache flushing is only necessary when multiple cores running the same -- 2.7.4