From 2bfecc160b8eba310a890d8ecbb8c3b74d885e83 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Wed, 12 Apr 2023 22:18:54 +0000 Subject: [PATCH] [vm] Update to constexpr in runtime/vm. TEST=build Change-Id: I2dd8ae69764af27f480a19995b491e98f52476ae Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293902 Reviewed-by: Liam Appelbe Commit-Queue: Ryan Macnak --- runtime/docs/gc.md | 6 +- runtime/vm/app_snapshot.cc | 2 +- runtime/vm/app_snapshot.h | 4 +- runtime/vm/bit_set.h | 2 +- runtime/vm/bitfield.h | 4 +- runtime/vm/bitmap_test.cc | 4 +- runtime/vm/bootstrap.cc | 3 +- runtime/vm/class_table.h | 4 +- runtime/vm/code_descriptors.h | 12 +- runtime/vm/code_patcher_arm64.cc | 2 +- runtime/vm/code_patcher_ia32.cc | 10 +- runtime/vm/constants_arm.h | 254 ++++++++++---------- runtime/vm/constants_arm64.h | 259 ++++++++++---------- runtime/vm/constants_ia32.h | 224 ++++++++--------- runtime/vm/constants_riscv.h | 121 +++++----- runtime/vm/constants_x64.h | 320 ++++++++++++------------- runtime/vm/dart_api_impl.cc | 8 +- runtime/vm/dart_api_impl_test.cc | 32 +-- runtime/vm/dart_api_state.h | 18 +- runtime/vm/datastream.h | 16 +- runtime/vm/deopt_instructions.cc | 4 +- runtime/vm/deopt_instructions.h | 2 +- runtime/vm/double_conversion.cc | 60 ++--- runtime/vm/double_conversion.h | 6 - runtime/vm/double_internals.h | 19 +- runtime/vm/dwarf.h | 82 +++---- runtime/vm/elf.cc | 8 +- runtime/vm/exceptions.cc | 2 +- runtime/vm/field_table.h | 4 +- runtime/vm/globals.h | 4 +- runtime/vm/handles.h | 12 +- runtime/vm/handles_test.cc | 4 +- runtime/vm/hash_table.h | 30 +-- runtime/vm/instructions_arm.h | 10 +- runtime/vm/instructions_arm64.h | 16 +- runtime/vm/instructions_ia32.h | 8 +- runtime/vm/instructions_riscv.h | 2 +- runtime/vm/instructions_x64.h | 10 +- runtime/vm/isolate.cc | 8 +- runtime/vm/isolate_test.cc | 7 +- runtime/vm/json_writer.cc | 2 +- runtime/vm/kernel.h | 2 +- runtime/vm/kernel_binary.h | 16 +- runtime/vm/kernel_isolate.cc | 20 -- runtime/vm/kernel_isolate.h | 28 ++- runtime/vm/memory_region_test.cc | 16 +- runtime/vm/message_snapshot.cc | 4 +- runtime/vm/native_entry.h | 4 +- runtime/vm/native_symbol_win.cc | 4 +- runtime/vm/object.cc | 18 +- runtime/vm/object.h | 212 ++++++++-------- runtime/vm/object_graph.cc | 6 +- runtime/vm/object_graph.h | 6 +- runtime/vm/object_id_ring.h | 6 +- runtime/vm/os_linux.cc | 14 +- runtime/vm/os_thread.h | 4 +- runtime/vm/os_win.cc | 4 +- runtime/vm/port_set.h | 2 +- runtime/vm/profiler.cc | 2 +- runtime/vm/profiler.h | 8 +- runtime/vm/profiler_service.h | 2 +- runtime/vm/profiler_test.cc | 2 +- runtime/vm/raw_object.h | 13 +- runtime/vm/regexp.cc | 62 ++--- runtime/vm/regexp.h | 36 +-- runtime/vm/regexp_assembler.h | 12 +- runtime/vm/regexp_assembler_bytecode.h | 2 +- runtime/vm/regexp_ast.h | 2 +- runtime/vm/regexp_bytecodes.h | 5 +- runtime/vm/regexp_interpreter.cc | 2 +- runtime/vm/regexp_parser.cc | 2 +- runtime/vm/regexp_parser.h | 6 +- runtime/vm/report.h | 4 +- runtime/vm/ring_buffer.h | 2 +- runtime/vm/runtime_entry.cc | 4 +- runtime/vm/scopes.cc | 2 +- runtime/vm/scopes.h | 6 +- runtime/vm/service.cc | 12 +- runtime/vm/simulator_arm.h | 6 +- runtime/vm/simulator_arm64.h | 6 +- runtime/vm/simulator_riscv.h | 2 +- runtime/vm/simulator_x64.h | 2 +- runtime/vm/snapshot.h | 16 +- runtime/vm/snapshot_test.cc | 10 +- runtime/vm/stack_frame.h | 2 +- runtime/vm/stack_frame_arm.h | 31 +-- runtime/vm/stack_frame_arm64.h | 31 +-- runtime/vm/stack_frame_ia32.h | 29 +-- runtime/vm/stack_frame_riscv.h | 31 +-- runtime/vm/stack_frame_x64.h | 31 +-- runtime/vm/symbols.h | 4 +- runtime/vm/tagged_pointer.h | 17 +- runtime/vm/tags.h | 6 +- runtime/vm/thread_barrier_test.cc | 4 +- runtime/vm/thread_interrupter.h | 2 +- runtime/vm/thread_test.cc | 8 +- runtime/vm/timeline.h | 6 +- runtime/vm/token.h | 2 +- runtime/vm/unibrow.cc | 88 +++---- runtime/vm/unibrow.h | 12 +- runtime/vm/unicode.cc | 4 +- runtime/vm/unicode_test.cc | 2 +- runtime/vm/unit_test.h | 10 +- runtime/vm/utils_test.cc | 2 +- runtime/vm/zone.h | 10 +- runtime/vm/zone_test.cc | 2 +- 106 files changed, 1261 insertions(+), 1272 deletions(-) diff --git a/runtime/docs/gc.md b/runtime/docs/gc.md index 2b925f6046d..63a26f617ea 100644 --- a/runtime/docs/gc.md +++ b/runtime/docs/gc.md @@ -110,9 +110,9 @@ enum HeaderBits { ... }; -static const intptr_t kGenerationalBarrierMask = 1 << kNewBit; -static const intptr_t kIncrementalBarrierMask = 1 << kOldAndNotMarkedBit; -static const intptr_t kBarrierOverlapShift = 2; +static constexpr intptr_t kGenerationalBarrierMask = 1 << kNewBit; +static constexpr intptr_t kIncrementalBarrierMask = 1 << kOldAndNotMarkedBit; +static constexpr intptr_t kBarrierOverlapShift = 2; COMPILE_ASSERT(kOldAndNotMarkedBit + kBarrierOverlapShift == kOldBit); COMPILE_ASSERT(kNewBit + kBarrierOverlapShift == kOldAndNotRememberedBit); diff --git a/runtime/vm/app_snapshot.cc b/runtime/vm/app_snapshot.cc index 0dd1576b4b0..b33ac56b6f9 100644 --- a/runtime/vm/app_snapshot.cc +++ b/runtime/vm/app_snapshot.cc @@ -6742,7 +6742,7 @@ class UnitDeserializationRoots : public DeserializationRoots { }; #if defined(DEBUG) -static const int32_t kSectionMarker = 0xABAB; +static constexpr int32_t kSectionMarker = 0xABAB; #endif Serializer::Serializer(Thread* thread, diff --git a/runtime/vm/app_snapshot.h b/runtime/vm/app_snapshot.h index df31e82280f..909849b01d1 100644 --- a/runtime/vm/app_snapshot.h +++ b/runtime/vm/app_snapshot.h @@ -197,7 +197,7 @@ static constexpr intptr_t kFirstReference = 1; // Reference value for traced objects that have not been allocated their final // reference ID. -static const intptr_t kUnallocatedReference = -1; +static constexpr intptr_t kUnallocatedReference = -1; static constexpr bool IsAllocatedReference(intptr_t ref) { return ref > kUnreachableReference; @@ -820,7 +820,7 @@ class Deserializer : public ThreadStackResource { class FullSnapshotWriter { public: - static const intptr_t kInitialSize = 64 * KB; + static constexpr intptr_t kInitialSize = 64 * KB; FullSnapshotWriter(Snapshot::Kind kind, NonStreamingWriteStream* vm_snapshot_data, NonStreamingWriteStream* isolate_snapshot_data, diff --git a/runtime/vm/bit_set.h b/runtime/vm/bit_set.h index c16cceabf71..498b53ef9c2 100644 --- a/runtime/vm/bit_set.h +++ b/runtime/vm/bit_set.h @@ -91,7 +91,7 @@ class BitSet { intptr_t Size() const { return N; } private: - static const int kLengthInWords = 1 + ((N - 1) / kBitsPerWord); + static constexpr int kLengthInWords = 1 + ((N - 1) / kBitsPerWord); uword data_[kLengthInWords]; }; diff --git a/runtime/vm/bitfield.h b/runtime/vm/bitfield.h index 630f08fe0fb..c36b36d8626 100644 --- a/runtime/vm/bitfield.h +++ b/runtime/vm/bitfield.h @@ -122,7 +122,7 @@ class AtomicBitFieldContainer : AtomicBitFieldContainerBase { std::atomic field_; }; -static const uword kUwordOne = 1U; +static constexpr uword kUwordOne = 1U; // BitField is a template for encoding and decoding a value of type T // inside a storage of type S. @@ -141,7 +141,7 @@ class BitField { static_assert(!sign_extend || std::is_signed::value, "Should only sign extend signed bitfield types"); - static const intptr_t kNextBit = position + size; + static constexpr intptr_t kNextBit = position + size; // Tells whether the provided value fits into the bit field. static constexpr bool is_valid(T value) { diff --git a/runtime/vm/bitmap_test.cc b/runtime/vm/bitmap_test.cc index 0e7837f4685..aab0ef4f3d2 100644 --- a/runtime/vm/bitmap_test.cc +++ b/runtime/vm/bitmap_test.cc @@ -13,8 +13,8 @@ namespace dart { // 0x4 is just a placeholder PC offset because no entry of a CSM should // have a PC offset of 0, otherwise internal assumptions break. -static const uint32_t kTestPcOffset = 0x4; -static const intptr_t kTestSpillSlotBitCount = 0; +static constexpr uint32_t kTestPcOffset = 0x4; +static constexpr intptr_t kTestSpillSlotBitCount = 0; static CompressedStackMapsPtr MapsFromBuilder(Zone* zone, BitmapBuilder* bmap) { CompressedStackMapsBuilder builder(zone); diff --git a/runtime/vm/bootstrap.cc b/runtime/vm/bootstrap.cc index d9f7a43f04a..84701e7adac 100644 --- a/runtime/vm/bootstrap.cc +++ b/runtime/vm/bootstrap.cc @@ -38,7 +38,8 @@ static const BootstrapLibProps bootstrap_libraries[] = { #undef MAKE_PROPERTIES -static const intptr_t kBootstrapLibraryCount = ARRAY_SIZE(bootstrap_libraries); +static constexpr intptr_t kBootstrapLibraryCount = + ARRAY_SIZE(bootstrap_libraries); static void Finish(Thread* thread) { Bootstrap::SetupNativeResolver(); if (!ClassFinalizer::ProcessPendingClasses()) { diff --git a/runtime/vm/class_table.h b/runtime/vm/class_table.h index cc003c40bf2..85cec39b40e 100644 --- a/runtime/vm/class_table.h +++ b/runtime/vm/class_table.h @@ -521,9 +521,9 @@ class ClassTable : public MallocAllocated { const char* name, char** error); friend class IsolateGroup; // for table() - static const int kInitialCapacity = 512; + static constexpr int kInitialCapacity = 512; - static const intptr_t kTopLevelCidOffset = kClassIdTagMax + 1; + static constexpr intptr_t kTopLevelCidOffset = kClassIdTagMax + 1; ClassTable(const ClassTable& original) : allocator_(original.allocator_), diff --git a/runtime/vm/code_descriptors.h b/runtime/vm/code_descriptors.h index cbec7edeead..af1a947b15c 100644 --- a/runtime/vm/code_descriptors.h +++ b/runtime/vm/code_descriptors.h @@ -14,7 +14,7 @@ namespace dart { -static const intptr_t kInvalidTryIndex = -1; +static constexpr intptr_t kInvalidTryIndex = -1; class DescriptorList : public ZoneAllocated { public: @@ -191,11 +191,11 @@ struct InstructionSource { }; struct CodeSourceMapOps : AllStatic { - static const uint8_t kChangePosition = 0; - static const uint8_t kAdvancePC = 1; - static const uint8_t kPushFunction = 2; - static const uint8_t kPopFunction = 3; - static const uint8_t kNullCheck = 4; + static constexpr uint8_t kChangePosition = 0; + static constexpr uint8_t kAdvancePC = 1; + static constexpr uint8_t kPushFunction = 2; + static constexpr uint8_t kPopFunction = 3; + static constexpr uint8_t kNullCheck = 4; static uint8_t Read(ReadStream* stream, int32_t* arg1, diff --git a/runtime/vm/code_patcher_arm64.cc b/runtime/vm/code_patcher_arm64.cc index ca27d6ab0c8..b4a270516aa 100644 --- a/runtime/vm/code_patcher_arm64.cc +++ b/runtime/vm/code_patcher_arm64.cc @@ -34,7 +34,7 @@ class PoolPointerCall : public ValueObject { } private: - static const int kCallPatternSize = 3 * Instr::kInstrSize; + static constexpr int kCallPatternSize = 3 * Instr::kInstrSize; uword end_; const ObjectPool& object_pool_; Register reg_; diff --git a/runtime/vm/code_patcher_ia32.cc b/runtime/vm/code_patcher_ia32.cc index bb2dad1ea56..59558c84435 100644 --- a/runtime/vm/code_patcher_ia32.cc +++ b/runtime/vm/code_patcher_ia32.cc @@ -31,9 +31,9 @@ class UnoptimizedCall : public ValueObject { return LoadUnaligned(reinterpret_cast(start_ + 1)); } - static const int kMovInstructionSize = 5; - static const int kCallInstructionSize = 3; - static const int kPatternSize = + static constexpr int kMovInstructionSize = 5; + static constexpr int kCallInstructionSize = 3; + static constexpr int kPatternSize = 2 * kMovInstructionSize + kCallInstructionSize; private: @@ -160,8 +160,8 @@ class StaticCall : public ValueObject { target.ptr(), Thread::Current()); } - static const int kMovInstructionSize = 5; - static const int kCallInstructionSize = 3; + static constexpr int kMovInstructionSize = 5; + static constexpr int kCallInstructionSize = 3; private: uword return_address() const { diff --git a/runtime/vm/constants_arm.h b/runtime/vm/constants_arm.h index 9acd0cdea08..e3537ef2d57 100644 --- a/runtime/vm/constants_arm.h +++ b/runtime/vm/constants_arm.h @@ -335,17 +335,17 @@ const Register kWriteBarrierSlotReg = R9; // Common ABI for shared slow path stubs. struct SharedSlowPathStubABI { - static const Register kResultReg = R0; + static constexpr Register kResultReg = R0; }; // ABI for instantiation stubs. struct InstantiationABI { - static const Register kUninstantiatedTypeArgumentsReg = R3; - static const Register kInstantiatorTypeArgumentsReg = R2; - static const Register kFunctionTypeArgumentsReg = R1; - static const Register kResultTypeArgumentsReg = R0; - static const Register kResultTypeReg = R0; - static const Register kScratchReg = R8; + static constexpr Register kUninstantiatedTypeArgumentsReg = R3; + static constexpr Register kInstantiatorTypeArgumentsReg = R2; + static constexpr Register kFunctionTypeArgumentsReg = R1; + static constexpr Register kResultTypeArgumentsReg = R0; + static constexpr Register kResultTypeReg = R0; + static constexpr Register kScratchReg = R8; }; // Registers in addition to those listed in InstantiationABI used inside the @@ -353,34 +353,34 @@ struct InstantiationABI { struct InstantiateTAVInternalRegs { // The set of registers that must be pushed/popped when probing a hash-based // cache due to overlap with the registers in InstantiationABI. - static const intptr_t kSavedRegisters = + static constexpr intptr_t kSavedRegisters = #if defined(DART_PRECOMPILER) (1 << DISPATCH_TABLE_REG) | #endif (1 << InstantiationABI::kUninstantiatedTypeArgumentsReg); // Additional registers used to probe hash-based caches. - static const Register kEntryStartReg = R9; - static const Register kProbeMaskReg = R4; - static const Register kProbeDistanceReg = DISPATCH_TABLE_REG; - static const Register kCurrentEntryIndexReg = + static constexpr Register kEntryStartReg = R9; + static constexpr Register kProbeMaskReg = R4; + static constexpr Register kProbeDistanceReg = DISPATCH_TABLE_REG; + static constexpr Register kCurrentEntryIndexReg = InstantiationABI::kUninstantiatedTypeArgumentsReg; }; // Registers in addition to those listed in TypeTestABI used inside the // implementation of type testing stubs that are _not_ preserved. struct TTSInternalRegs { - static const Register kInstanceTypeArgumentsReg = R4; - static const Register kScratchReg = R9; - static const Register kSubTypeArgumentReg = R3; - static const Register kSuperTypeArgumentReg = R8; + static constexpr Register kInstanceTypeArgumentsReg = R4; + static constexpr Register kScratchReg = R9; + static constexpr Register kSubTypeArgumentReg = R3; + static constexpr Register kSuperTypeArgumentReg = R8; // Must be pushed/popped whenever generic type arguments are being checked as // they overlap with registers in TypeTestABI. - static const intptr_t kSavedTypeArgumentRegisters = + static constexpr intptr_t kSavedTypeArgumentRegisters = (1 << kSubTypeArgumentReg) | (1 << kSuperTypeArgumentReg); - static const intptr_t kInternalRegisters = + static constexpr intptr_t kInternalRegisters = ((1 << kInstanceTypeArgumentsReg) | (1 << kScratchReg) | (1 << kSubTypeArgumentReg) | (1 << kSuperTypeArgumentReg)) & ~kSavedTypeArgumentRegisters; @@ -389,52 +389,53 @@ struct TTSInternalRegs { // Registers in addition to those listed in TypeTestABI used inside the // implementation of subtype test cache stubs that are _not_ preserved. struct STCInternalRegs { - static const Register kInstanceCidOrSignatureReg = R9; + static constexpr Register kInstanceCidOrSignatureReg = R9; - static const intptr_t kInternalRegisters = (1 << kInstanceCidOrSignatureReg); + static constexpr intptr_t kInternalRegisters = + (1 << kInstanceCidOrSignatureReg); }; // Calling convention when calling TypeTestingStub and SubtypeTestCacheStub. struct TypeTestABI { - static const Register kInstanceReg = R0; - static const Register kDstTypeReg = R8; - static const Register kInstantiatorTypeArgumentsReg = R2; - static const Register kFunctionTypeArgumentsReg = R1; - static const Register kSubtypeTestCacheReg = R3; - static const Register kScratchReg = R4; + static constexpr Register kInstanceReg = R0; + static constexpr Register kDstTypeReg = R8; + static constexpr Register kInstantiatorTypeArgumentsReg = R2; + static constexpr Register kFunctionTypeArgumentsReg = R1; + static constexpr Register kSubtypeTestCacheReg = R3; + static constexpr Register kScratchReg = R4; // For calls to InstanceOfStub. - static const Register kInstanceOfResultReg = kInstanceReg; + static constexpr Register kInstanceOfResultReg = kInstanceReg; // For calls to SubtypeNTestCacheStub. Must be saved by the caller if the // original value is needed after the call. - static const Register kSubtypeTestCacheResultReg = kSubtypeTestCacheReg; + static constexpr Register kSubtypeTestCacheResultReg = kSubtypeTestCacheReg; // Registers that need saving across SubtypeTestCacheStub calls. - static const intptr_t kSubtypeTestCacheStubCallerSavedRegisters = + static constexpr intptr_t kSubtypeTestCacheStubCallerSavedRegisters = 1 << kSubtypeTestCacheReg; - static const intptr_t kPreservedAbiRegisters = + static constexpr intptr_t kPreservedAbiRegisters = (1 << kInstanceReg) | (1 << kDstTypeReg) | (1 << kInstantiatorTypeArgumentsReg) | (1 << kFunctionTypeArgumentsReg); - static const intptr_t kNonPreservedAbiRegisters = + static constexpr intptr_t kNonPreservedAbiRegisters = TTSInternalRegs::kInternalRegisters | STCInternalRegs::kInternalRegisters | (1 << kSubtypeTestCacheReg) | (1 << kScratchReg) | (1 << kSubtypeTestCacheResultReg) | (1 << CODE_REG); - static const intptr_t kAbiRegisters = + static constexpr intptr_t kAbiRegisters = kPreservedAbiRegisters | kNonPreservedAbiRegisters; }; // Calling convention when calling AssertSubtypeStub. struct AssertSubtypeABI { - static const Register kSubTypeReg = R0; - static const Register kSuperTypeReg = R8; - static const Register kInstantiatorTypeArgumentsReg = R2; - static const Register kFunctionTypeArgumentsReg = R1; - static const Register kDstNameReg = R3; + static constexpr Register kSubTypeReg = R0; + static constexpr Register kSuperTypeReg = R8; + static constexpr Register kInstantiatorTypeArgumentsReg = R2; + static constexpr Register kFunctionTypeArgumentsReg = R1; + static constexpr Register kDstNameReg = R3; - static const intptr_t kAbiRegisters = + static constexpr intptr_t kAbiRegisters = (1 << kSubTypeReg) | (1 << kSuperTypeReg) | (1 << kInstantiatorTypeArgumentsReg) | (1 << kFunctionTypeArgumentsReg) | (1 << kDstNameReg); @@ -445,183 +446,183 @@ struct AssertSubtypeABI { // ABI for InitStaticFieldStub. struct InitStaticFieldABI { - static const Register kFieldReg = R2; - static const Register kResultReg = R0; + static constexpr Register kFieldReg = R2; + static constexpr Register kResultReg = R0; }; // Registers used inside the implementation of InitLateStaticFieldStub. struct InitLateStaticFieldInternalRegs { - static const Register kAddressReg = R3; - static const Register kScratchReg = R4; + static constexpr Register kAddressReg = R3; + static constexpr Register kScratchReg = R4; }; // ABI for InitInstanceFieldStub. struct InitInstanceFieldABI { - static const Register kInstanceReg = R1; - static const Register kFieldReg = R2; - static const Register kResultReg = R0; + static constexpr Register kInstanceReg = R1; + static constexpr Register kFieldReg = R2; + static constexpr Register kResultReg = R0; }; // Registers used inside the implementation of InitLateInstanceFieldStub. struct InitLateInstanceFieldInternalRegs { - static const Register kAddressReg = R3; - static const Register kScratchReg = R4; + static constexpr Register kAddressReg = R3; + static constexpr Register kScratchReg = R4; }; // ABI for LateInitializationError stubs. struct LateInitializationErrorABI { - static const Register kFieldReg = R9; + static constexpr Register kFieldReg = R9; }; // ABI for ThrowStub. struct ThrowABI { - static const Register kExceptionReg = R0; + static constexpr Register kExceptionReg = R0; }; // ABI for ReThrowStub. struct ReThrowABI { - static const Register kExceptionReg = R0; - static const Register kStackTraceReg = R1; + static constexpr Register kExceptionReg = R0; + static constexpr Register kStackTraceReg = R1; }; // ABI for AssertBooleanStub. struct AssertBooleanABI { - static const Register kObjectReg = R0; + static constexpr Register kObjectReg = R0; }; // ABI for RangeErrorStub. struct RangeErrorABI { - static const Register kLengthReg = R0; - static const Register kIndexReg = R1; + static constexpr Register kLengthReg = R0; + static constexpr Register kIndexReg = R1; }; // ABI for AllocateObjectStub. struct AllocateObjectABI { - static const Register kResultReg = R0; - static const Register kTypeArgumentsReg = R3; - static const Register kTagsReg = R2; + static constexpr Register kResultReg = R0; + static constexpr Register kTypeArgumentsReg = R3; + static constexpr Register kTagsReg = R2; }; // ABI for AllocateClosureStub. struct AllocateClosureABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kFunctionReg = R1; - static const Register kContextReg = R2; - static const Register kScratchReg = R4; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kFunctionReg = R1; + static constexpr Register kContextReg = R2; + static constexpr Register kScratchReg = R4; }; // ABI for AllocateMintShared*Stub. struct AllocateMintABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kTempReg = R1; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kTempReg = R1; }; // ABI for Allocate{Mint,Double,Float32x4,Float64x2}Stub. struct AllocateBoxABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kTempReg = R1; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kTempReg = R1; }; // ABI for AllocateArrayStub. struct AllocateArrayABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kLengthReg = R2; - static const Register kTypeArgumentsReg = R1; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kLengthReg = R2; + static constexpr Register kTypeArgumentsReg = R1; }; // ABI for AllocateRecordStub. struct AllocateRecordABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kShapeReg = R1; - static const Register kTemp1Reg = R2; - static const Register kTemp2Reg = R3; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kShapeReg = R1; + static constexpr Register kTemp1Reg = R2; + static constexpr Register kTemp2Reg = R3; }; // ABI for AllocateSmallRecordStub (AllocateRecord2, AllocateRecord2Named, // AllocateRecord3, AllocateRecord3Named). struct AllocateSmallRecordABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kShapeReg = R1; - static const Register kValue0Reg = R2; - static const Register kValue1Reg = R3; - static const Register kValue2Reg = R4; - static const Register kTempReg = R9; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kShapeReg = R1; + static constexpr Register kValue0Reg = R2; + static constexpr Register kValue1Reg = R3; + static constexpr Register kValue2Reg = R4; + static constexpr Register kTempReg = R9; }; // ABI for AllocateTypedDataArrayStub. struct AllocateTypedDataArrayABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kLengthReg = R4; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kLengthReg = R4; }; // ABI for BoxDoubleStub. struct BoxDoubleStubABI { - static const FpuRegister kValueReg = Q0; - static const Register kTempReg = R1; - static const Register kResultReg = R0; + static constexpr FpuRegister kValueReg = Q0; + static constexpr Register kTempReg = R1; + static constexpr Register kResultReg = R0; }; // ABI for DoubleToIntegerStub. struct DoubleToIntegerStubABI { - static const FpuRegister kInputReg = Q0; - static const Register kRecognizedKindReg = R0; - static const Register kResultReg = R0; + static constexpr FpuRegister kInputReg = Q0; + static constexpr Register kRecognizedKindReg = R0; + static constexpr Register kResultReg = R0; }; // ABI for SuspendStub (AwaitStub, AwaitWithTypeCheckStub, YieldAsyncStarStub, // SuspendSyncStarAtStartStub, SuspendSyncStarAtYieldStub). struct SuspendStubABI { - static const Register kArgumentReg = R0; - static const Register kTypeArgsReg = R1; // Can be the same as kTempReg - static const Register kTempReg = R1; - static const Register kFrameSizeReg = R2; - static const Register kSuspendStateReg = R3; - static const Register kFunctionDataReg = R4; - static const Register kSrcFrameReg = R8; - static const Register kDstFrameReg = R9; + static constexpr Register kArgumentReg = R0; + static constexpr Register kTypeArgsReg = R1; // Can be the same as kTempReg + static constexpr Register kTempReg = R1; + static constexpr Register kFrameSizeReg = R2; + static constexpr Register kSuspendStateReg = R3; + static constexpr Register kFunctionDataReg = R4; + static constexpr Register kSrcFrameReg = R8; + static constexpr Register kDstFrameReg = R9; }; // ABI for InitSuspendableFunctionStub (InitAsyncStub, InitAsyncStarStub, // InitSyncStarStub). struct InitSuspendableFunctionStubABI { - static const Register kTypeArgsReg = R0; + static constexpr Register kTypeArgsReg = R0; }; // ABI for ResumeStub struct ResumeStubABI { - static const Register kSuspendStateReg = R2; - static const Register kTempReg = R0; + static constexpr Register kSuspendStateReg = R2; + static constexpr Register kTempReg = R0; // Registers for the frame copying (the 1st part). - static const Register kFrameSizeReg = R1; - static const Register kSrcFrameReg = R3; - static const Register kDstFrameReg = R4; + static constexpr Register kFrameSizeReg = R1; + static constexpr Register kSrcFrameReg = R3; + static constexpr Register kDstFrameReg = R4; // Registers for control transfer. // (the 2nd part, can reuse registers from the 1st part) - static const Register kResumePcReg = R1; + static constexpr Register kResumePcReg = R1; // Can also reuse kSuspendStateReg but should not conflict with CODE_REG/PP. - static const Register kExceptionReg = R3; - static const Register kStackTraceReg = R4; + static constexpr Register kExceptionReg = R3; + static constexpr Register kStackTraceReg = R4; }; // ABI for ReturnStub (ReturnAsyncStub, ReturnAsyncNotFutureStub, // ReturnAsyncStarStub). struct ReturnStubABI { - static const Register kSuspendStateReg = R2; + static constexpr Register kSuspendStateReg = R2; }; // ABI for AsyncExceptionHandlerStub. struct AsyncExceptionHandlerStubABI { - static const Register kSuspendStateReg = R2; + static constexpr Register kSuspendStateReg = R2; }; // ABI for CloneSuspendStateStub. struct CloneSuspendStateStubABI { - static const Register kSourceReg = R0; - static const Register kDestinationReg = R1; - static const Register kTempReg = R2; - static const Register kFrameSizeReg = R3; - static const Register kSrcFrameReg = R4; - static const Register kDstFrameReg = R8; + static constexpr Register kSourceReg = R0; + static constexpr Register kDestinationReg = R1; + static constexpr Register kTempReg = R2; + static constexpr Register kFrameSizeReg = R3; + static constexpr Register kSrcFrameReg = R4; + static constexpr Register kDstFrameReg = R8; }; // ABI for DispatchTableNullErrorStub and consequently for all dispatch @@ -629,7 +630,7 @@ struct CloneSuspendStateStubABI { // register). This ABI is added to distinguish memory corruption errors from // null errors. struct DispatchTableNullErrorABI { - static const Register kClassIdReg = R0; + static constexpr Register kClassIdReg = R0; }; // TODO(regis): Add ABIs for type testing stubs and is-type test stubs instead @@ -688,19 +689,19 @@ const RegList kFpuRegistersWithoutSOverlap = class CallingConventions { public: - static const intptr_t kArgumentRegisters = kAbiArgumentCpuRegs; + static constexpr intptr_t kArgumentRegisters = kAbiArgumentCpuRegs; static const Register ArgumentRegisters[]; - static const intptr_t kNumArgRegs = 4; - static const Register kPointerToReturnStructRegisterCall = R0; + static constexpr intptr_t kNumArgRegs = 4; + static constexpr Register kPointerToReturnStructRegisterCall = R0; - static const intptr_t kFpuArgumentRegisters = 0; + static constexpr intptr_t kFpuArgumentRegisters = 0; static const FpuRegister FpuArgumentRegisters[]; - static const intptr_t kNumFpuArgRegs = 4; + static constexpr intptr_t kNumFpuArgRegs = 4; static const DRegister FpuDArgumentRegisters[]; - static const intptr_t kNumDFpuArgRegs = 8; + static constexpr intptr_t kNumDFpuArgRegs = 8; static const SRegister FpuSArgumentRegisters[]; - static const intptr_t kNumSFpuArgRegs = 16; + static constexpr intptr_t kNumSFpuArgRegs = 16; static constexpr bool kArgumentIntRegXorFpuReg = false; @@ -967,26 +968,27 @@ class Instr { public: enum { kInstrSize = 4, kInstrSizeLog2 = 2, kPCReadOffset = 8 }; - static const int32_t kNopInstruction = // nop + static constexpr int32_t kNopInstruction = // nop ((AL << kConditionShift) | (0x32 << 20) | (0xf << 12)); - static const int32_t kBreakPointCode = 0xdeb0; // For breakpoint. - static const int32_t kSimulatorBreakCode = 0xdeb2; // For breakpoint in sim. - static const int32_t kSimulatorRedirectCode = 0xca11; // For redirection. + static constexpr int32_t kBreakPointCode = 0xdeb0; // For breakpoint. + static constexpr int32_t kSimulatorBreakCode = + 0xdeb2; // For breakpoint in sim. + static constexpr int32_t kSimulatorRedirectCode = 0xca11; // For redirection. // Breakpoint instruction filling assembler code buffers in debug mode. - static const int32_t kBreakPointInstruction = // bkpt(0xdeb0) + static constexpr int32_t kBreakPointInstruction = // bkpt(0xdeb0) ((AL << kConditionShift) | (0x12 << 20) | (0xdeb << 8) | (0x7 << 4)); // Breakpoint instruction used by the simulator. // Should be distinct from kBreakPointInstruction and from a typical user // breakpoint inserted in generated code for debugging, e.g. bkpt(0). - static const int32_t kSimulatorBreakpointInstruction = + static constexpr int32_t kSimulatorBreakpointInstruction = // svc #kBreakpointSvcCode ((AL << kConditionShift) | (0xf << 24) | kSimulatorBreakCode); // Runtime call redirection instruction used by the simulator. - static const int32_t kSimulatorRedirectInstruction = + static constexpr int32_t kSimulatorRedirectInstruction = ((AL << kConditionShift) | (0xf << 24) | kSimulatorRedirectCode); // Get the raw instruction bits. diff --git a/runtime/vm/constants_arm64.h b/runtime/vm/constants_arm64.h index a780a4c28b3..6e21c6f6eaa 100644 --- a/runtime/vm/constants_arm64.h +++ b/runtime/vm/constants_arm64.h @@ -168,17 +168,17 @@ const Register kWriteBarrierSlotReg = R25; // Common ABI for shared slow path stubs. struct SharedSlowPathStubABI { - static const Register kResultReg = R0; + static constexpr Register kResultReg = R0; }; // ABI for instantiation stubs. struct InstantiationABI { - static const Register kUninstantiatedTypeArgumentsReg = R3; - static const Register kInstantiatorTypeArgumentsReg = R2; - static const Register kFunctionTypeArgumentsReg = R1; - static const Register kResultTypeArgumentsReg = R0; - static const Register kResultTypeReg = R0; - static const Register kScratchReg = R8; + static constexpr Register kUninstantiatedTypeArgumentsReg = R3; + static constexpr Register kInstantiatorTypeArgumentsReg = R2; + static constexpr Register kFunctionTypeArgumentsReg = R1; + static constexpr Register kResultTypeArgumentsReg = R0; + static constexpr Register kResultTypeReg = R0; + static constexpr Register kScratchReg = R8; }; // Registers in addition to those listed in InstantiationABI used inside the @@ -186,28 +186,28 @@ struct InstantiationABI { struct InstantiateTAVInternalRegs { // The set of registers that must be pushed/popped when probing a hash-based // cache due to overlap with the registers in InstantiationABI. - static const intptr_t kSavedRegisters = 0; + static constexpr intptr_t kSavedRegisters = 0; // Additional registers used to probe hash-based caches. - static const Register kEntryStartReg = R9; - static const Register kProbeMaskReg = R7; - static const Register kProbeDistanceReg = R6; - static const Register kCurrentEntryIndexReg = R10; + static constexpr Register kEntryStartReg = R9; + static constexpr Register kProbeMaskReg = R7; + static constexpr Register kProbeDistanceReg = R6; + static constexpr Register kCurrentEntryIndexReg = R10; }; // Registers in addition to those listed in TypeTestABI used inside the // implementation of type testing stubs that are _not_ preserved. struct TTSInternalRegs { - static const Register kInstanceTypeArgumentsReg = R7; - static const Register kScratchReg = R9; - static const Register kSubTypeArgumentReg = R5; - static const Register kSuperTypeArgumentReg = R6; + static constexpr Register kInstanceTypeArgumentsReg = R7; + static constexpr Register kScratchReg = R9; + static constexpr Register kSubTypeArgumentReg = R5; + static constexpr Register kSuperTypeArgumentReg = R6; // Must be pushed/popped whenever generic type arguments are being checked as // they overlap with registers in TypeTestABI. - static const intptr_t kSavedTypeArgumentRegisters = 0; + static constexpr intptr_t kSavedTypeArgumentRegisters = 0; - static const intptr_t kInternalRegisters = + static constexpr intptr_t kInternalRegisters = ((1 << kInstanceTypeArgumentsReg) | (1 << kScratchReg) | (1 << kSubTypeArgumentReg) | (1 << kSuperTypeArgumentReg)) & ~kSavedTypeArgumentRegisters; @@ -216,12 +216,12 @@ struct TTSInternalRegs { // Registers in addition to those listed in TypeTestABI used inside the // implementation of subtype test cache stubs that are _not_ preserved. struct STCInternalRegs { - static const Register kInstanceCidOrSignatureReg = R6; - static const Register kInstanceInstantiatorTypeArgumentsReg = R5; - static const Register kInstanceParentFunctionTypeArgumentsReg = R9; - static const Register kInstanceDelayedFunctionTypeArgumentsReg = R10; + static constexpr Register kInstanceCidOrSignatureReg = R6; + static constexpr Register kInstanceInstantiatorTypeArgumentsReg = R5; + static constexpr Register kInstanceParentFunctionTypeArgumentsReg = R9; + static constexpr Register kInstanceDelayedFunctionTypeArgumentsReg = R10; - static const intptr_t kInternalRegisters = + static constexpr intptr_t kInternalRegisters = (1 << kInstanceCidOrSignatureReg) | (1 << kInstanceInstantiatorTypeArgumentsReg) | (1 << kInstanceParentFunctionTypeArgumentsReg) | @@ -230,45 +230,45 @@ struct STCInternalRegs { // Calling convention when calling TypeTestingStub and SubtypeTestCacheStub. struct TypeTestABI { - static const Register kInstanceReg = R0; - static const Register kDstTypeReg = R8; - static const Register kInstantiatorTypeArgumentsReg = R2; - static const Register kFunctionTypeArgumentsReg = R1; - static const Register kSubtypeTestCacheReg = R3; - static const Register kScratchReg = R4; + static constexpr Register kInstanceReg = R0; + static constexpr Register kDstTypeReg = R8; + static constexpr Register kInstantiatorTypeArgumentsReg = R2; + static constexpr Register kFunctionTypeArgumentsReg = R1; + static constexpr Register kSubtypeTestCacheReg = R3; + static constexpr Register kScratchReg = R4; // For calls to InstanceOfStub. - static const Register kInstanceOfResultReg = kInstanceReg; + static constexpr Register kInstanceOfResultReg = kInstanceReg; // For calls to SubtypeNTestCacheStub. Must not overlap with any other // registers above, for it is also used internally as kNullReg in those stubs. - static const Register kSubtypeTestCacheResultReg = R7; + static constexpr Register kSubtypeTestCacheResultReg = R7; // Registers that need saving across SubtypeTestCacheStub calls. - static const intptr_t kSubtypeTestCacheStubCallerSavedRegisters = + static constexpr intptr_t kSubtypeTestCacheStubCallerSavedRegisters = 1 << kSubtypeTestCacheReg; - static const intptr_t kPreservedAbiRegisters = + static constexpr intptr_t kPreservedAbiRegisters = (1 << kInstanceReg) | (1 << kDstTypeReg) | (1 << kInstantiatorTypeArgumentsReg) | (1 << kFunctionTypeArgumentsReg); - static const intptr_t kNonPreservedAbiRegisters = + static constexpr intptr_t kNonPreservedAbiRegisters = TTSInternalRegs::kInternalRegisters | STCInternalRegs::kInternalRegisters | (1 << kSubtypeTestCacheReg) | (1 << kScratchReg) | (1 << kSubtypeTestCacheResultReg) | (1 << CODE_REG); - static const intptr_t kAbiRegisters = + static constexpr intptr_t kAbiRegisters = kPreservedAbiRegisters | kNonPreservedAbiRegisters; }; // Calling convention when calling AssertSubtypeStub. struct AssertSubtypeABI { - static const Register kSubTypeReg = R0; - static const Register kSuperTypeReg = R8; - static const Register kInstantiatorTypeArgumentsReg = R2; - static const Register kFunctionTypeArgumentsReg = R1; - static const Register kDstNameReg = R3; + static constexpr Register kSubTypeReg = R0; + static constexpr Register kSuperTypeReg = R8; + static constexpr Register kInstantiatorTypeArgumentsReg = R2; + static constexpr Register kFunctionTypeArgumentsReg = R1; + static constexpr Register kDstNameReg = R3; - static const intptr_t kAbiRegisters = + static constexpr intptr_t kAbiRegisters = (1 << kSubTypeReg) | (1 << kSuperTypeReg) | (1 << kInstantiatorTypeArgumentsReg) | (1 << kFunctionTypeArgumentsReg) | (1 << kDstNameReg); @@ -279,183 +279,183 @@ struct AssertSubtypeABI { // ABI for InitStaticFieldStub. struct InitStaticFieldABI { - static const Register kFieldReg = R2; - static const Register kResultReg = R0; + static constexpr Register kFieldReg = R2; + static constexpr Register kResultReg = R0; }; // Registers used inside the implementation of InitLateStaticFieldStub. struct InitLateStaticFieldInternalRegs { - static const Register kAddressReg = R3; - static const Register kScratchReg = R4; + static constexpr Register kAddressReg = R3; + static constexpr Register kScratchReg = R4; }; // ABI for InitInstanceFieldStub. struct InitInstanceFieldABI { - static const Register kInstanceReg = R1; - static const Register kFieldReg = R2; - static const Register kResultReg = R0; + static constexpr Register kInstanceReg = R1; + static constexpr Register kFieldReg = R2; + static constexpr Register kResultReg = R0; }; // Registers used inside the implementation of InitLateInstanceFieldStub. struct InitLateInstanceFieldInternalRegs { - static const Register kAddressReg = R3; - static const Register kScratchReg = R4; + static constexpr Register kAddressReg = R3; + static constexpr Register kScratchReg = R4; }; // ABI for LateInitializationError stubs. struct LateInitializationErrorABI { - static const Register kFieldReg = R9; + static constexpr Register kFieldReg = R9; }; // ABI for ThrowStub. struct ThrowABI { - static const Register kExceptionReg = R0; + static constexpr Register kExceptionReg = R0; }; // ABI for ReThrowStub. struct ReThrowABI { - static const Register kExceptionReg = R0; - static const Register kStackTraceReg = R1; + static constexpr Register kExceptionReg = R0; + static constexpr Register kStackTraceReg = R1; }; // ABI for AssertBooleanStub. struct AssertBooleanABI { - static const Register kObjectReg = R0; + static constexpr Register kObjectReg = R0; }; // ABI for RangeErrorStub. struct RangeErrorABI { - static const Register kLengthReg = R0; - static const Register kIndexReg = R1; + static constexpr Register kLengthReg = R0; + static constexpr Register kIndexReg = R1; }; // ABI for AllocateObjectStub. struct AllocateObjectABI { - static const Register kResultReg = R0; - static const Register kTypeArgumentsReg = R1; - static const Register kTagsReg = R2; + static constexpr Register kResultReg = R0; + static constexpr Register kTypeArgumentsReg = R1; + static constexpr Register kTagsReg = R2; }; // ABI for AllocateClosureStub. struct AllocateClosureABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kFunctionReg = R1; - static const Register kContextReg = R2; - static const Register kScratchReg = R4; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kFunctionReg = R1; + static constexpr Register kContextReg = R2; + static constexpr Register kScratchReg = R4; }; // ABI for AllocateMintShared*Stub. struct AllocateMintABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kTempReg = R1; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kTempReg = R1; }; // ABI for Allocate{Mint,Double,Float32x4,Float64x2}Stub. struct AllocateBoxABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kTempReg = R1; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kTempReg = R1; }; // ABI for AllocateArrayStub. struct AllocateArrayABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kLengthReg = R2; - static const Register kTypeArgumentsReg = R1; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kLengthReg = R2; + static constexpr Register kTypeArgumentsReg = R1; }; // ABI for AllocateRecordStub. struct AllocateRecordABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kShapeReg = R1; - static const Register kTemp1Reg = R2; - static const Register kTemp2Reg = R3; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kShapeReg = R1; + static constexpr Register kTemp1Reg = R2; + static constexpr Register kTemp2Reg = R3; }; // ABI for AllocateSmallRecordStub (AllocateRecord2, AllocateRecord2Named, // AllocateRecord3, AllocateRecord3Named). struct AllocateSmallRecordABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kShapeReg = R1; - static const Register kValue0Reg = R2; - static const Register kValue1Reg = R3; - static const Register kValue2Reg = R4; - static const Register kTempReg = R5; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kShapeReg = R1; + static constexpr Register kValue0Reg = R2; + static constexpr Register kValue1Reg = R3; + static constexpr Register kValue2Reg = R4; + static constexpr Register kTempReg = R5; }; // ABI for AllocateTypedDataArrayStub. struct AllocateTypedDataArrayABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kLengthReg = R4; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kLengthReg = R4; }; // ABI for BoxDoubleStub. struct BoxDoubleStubABI { - static const FpuRegister kValueReg = V0; - static const Register kTempReg = R1; - static const Register kResultReg = R0; + static constexpr FpuRegister kValueReg = V0; + static constexpr Register kTempReg = R1; + static constexpr Register kResultReg = R0; }; // ABI for DoubleToIntegerStub. struct DoubleToIntegerStubABI { - static const FpuRegister kInputReg = V0; - static const Register kRecognizedKindReg = R0; - static const Register kResultReg = R0; + static constexpr FpuRegister kInputReg = V0; + static constexpr Register kRecognizedKindReg = R0; + static constexpr Register kResultReg = R0; }; // ABI for SuspendStub (AwaitStub, AwaitWithTypeCheckStub, YieldAsyncStarStub, // SuspendSyncStarAtStartStub, SuspendSyncStarAtYieldStub). struct SuspendStubABI { - static const Register kArgumentReg = R0; - static const Register kTypeArgsReg = R1; // Can be the same as kTempReg - static const Register kTempReg = R1; - static const Register kFrameSizeReg = R2; - static const Register kSuspendStateReg = R3; - static const Register kFunctionDataReg = R4; - static const Register kSrcFrameReg = R5; - static const Register kDstFrameReg = R6; + static constexpr Register kArgumentReg = R0; + static constexpr Register kTypeArgsReg = R1; // Can be the same as kTempReg + static constexpr Register kTempReg = R1; + static constexpr Register kFrameSizeReg = R2; + static constexpr Register kSuspendStateReg = R3; + static constexpr Register kFunctionDataReg = R4; + static constexpr Register kSrcFrameReg = R5; + static constexpr Register kDstFrameReg = R6; }; // ABI for InitSuspendableFunctionStub (InitAsyncStub, InitAsyncStarStub, // InitSyncStarStub). struct InitSuspendableFunctionStubABI { - static const Register kTypeArgsReg = R0; + static constexpr Register kTypeArgsReg = R0; }; // ABI for ResumeStub struct ResumeStubABI { - static const Register kSuspendStateReg = R2; - static const Register kTempReg = R0; + static constexpr Register kSuspendStateReg = R2; + static constexpr Register kTempReg = R0; // Registers for the frame copying (the 1st part). - static const Register kFrameSizeReg = R1; - static const Register kSrcFrameReg = R3; - static const Register kDstFrameReg = R4; + static constexpr Register kFrameSizeReg = R1; + static constexpr Register kSrcFrameReg = R3; + static constexpr Register kDstFrameReg = R4; // Registers for control transfer. // (the 2nd part, can reuse registers from the 1st part) - static const Register kResumePcReg = R1; + static constexpr Register kResumePcReg = R1; // Can also reuse kSuspendStateReg but should not conflict with CODE_REG/PP. - static const Register kExceptionReg = R3; - static const Register kStackTraceReg = R4; + static constexpr Register kExceptionReg = R3; + static constexpr Register kStackTraceReg = R4; }; // ABI for ReturnStub (ReturnAsyncStub, ReturnAsyncNotFutureStub, // ReturnAsyncStarStub). struct ReturnStubABI { - static const Register kSuspendStateReg = R2; + static constexpr Register kSuspendStateReg = R2; }; // ABI for AsyncExceptionHandlerStub. struct AsyncExceptionHandlerStubABI { - static const Register kSuspendStateReg = R2; + static constexpr Register kSuspendStateReg = R2; }; // ABI for CloneSuspendStateStub. struct CloneSuspendStateStubABI { - static const Register kSourceReg = R0; - static const Register kDestinationReg = R1; - static const Register kTempReg = R2; - static const Register kFrameSizeReg = R3; - static const Register kSrcFrameReg = R4; - static const Register kDstFrameReg = R5; + static constexpr Register kSourceReg = R0; + static constexpr Register kDestinationReg = R1; + static constexpr Register kTempReg = R2; + static constexpr Register kFrameSizeReg = R3; + static constexpr Register kSrcFrameReg = R4; + static constexpr Register kDstFrameReg = R5; }; // ABI for DispatchTableNullErrorStub and consequently for all dispatch @@ -463,7 +463,7 @@ struct CloneSuspendStateStubABI { // register). This ABI is added to distinguish memory corruption errors from // null errors. struct DispatchTableNullErrorABI { - static const Register kClassIdReg = R0; + static constexpr Register kClassIdReg = R0; }; // TODO(regis): Add ABIs for type testing stubs and is-type test stubs instead @@ -546,21 +546,21 @@ constexpr int kStoreBufferWrapperSize = 32; class CallingConventions { public: - static const intptr_t kArgumentRegisters = kAbiArgumentCpuRegs; + static constexpr intptr_t kArgumentRegisters = kAbiArgumentCpuRegs; static const Register ArgumentRegisters[]; - static const intptr_t kNumArgRegs = 8; + static constexpr intptr_t kNumArgRegs = 8; // The native ABI uses R8 to pass the pointer to the memory preallocated for // struct return values. Arm64 is the only ABI in which this pointer is _not_ // in ArgumentRegisters[0] or on the stack. - static const Register kPointerToReturnStructRegisterCall = R8; - static const Register kPointerToReturnStructRegisterReturn = R8; + static constexpr Register kPointerToReturnStructRegisterCall = R8; + static constexpr Register kPointerToReturnStructRegisterReturn = R8; static const FpuRegister FpuArgumentRegisters[]; - static const intptr_t kFpuArgumentRegisters = + static constexpr intptr_t kFpuArgumentRegisters = R(V0) | R(V1) | R(V2) | R(V3) | R(V4) | R(V5) | R(V6) | R(V7); - static const intptr_t kNumFpuArgRegs = 8; + static constexpr intptr_t kNumFpuArgRegs = 8; - static const bool kArgumentIntRegXorFpuReg = false; + static constexpr bool kArgumentIntRegXorFpuReg = false; static constexpr intptr_t kCalleeSaveCpuRegisters = kAbiPreservedCpuRegs; @@ -1311,25 +1311,26 @@ class Instr { enum class WideSize { k32Bits, k64Bits }; - static const int32_t kNopInstruction = HINT; // hint #0 === nop. + static constexpr int32_t kNopInstruction = HINT; // hint #0 === nop. // Reserved brk and hlt instruction codes. - static const int32_t kBreakPointCode = 0xdeb0; // For breakpoint. - static const int32_t kSimulatorBreakCode = 0xdeb2; // For breakpoint in sim. - static const int32_t kSimulatorRedirectCode = 0xca11; // For redirection. + static constexpr int32_t kBreakPointCode = 0xdeb0; // For breakpoint. + static constexpr int32_t kSimulatorBreakCode = + 0xdeb2; // For breakpoint in sim. + static constexpr int32_t kSimulatorRedirectCode = 0xca11; // For redirection. // Breakpoint instruction filling assembler code buffers in debug mode. - static const int32_t kBreakPointInstruction = // brk(0xdeb0). + static constexpr int32_t kBreakPointInstruction = // brk(0xdeb0). BRK | (kBreakPointCode << kImm16Shift); // Breakpoint instruction used by the simulator. // Should be distinct from kBreakPointInstruction and from a typical user // breakpoint inserted in generated code for debugging, e.g. brk(0). - static const int32_t kSimulatorBreakpointInstruction = + static constexpr int32_t kSimulatorBreakpointInstruction = HLT | (kSimulatorBreakCode << kImm16Shift); // Runtime call redirection instruction used by the simulator. - static const int32_t kSimulatorRedirectInstruction = + static constexpr int32_t kSimulatorRedirectInstruction = HLT | (kSimulatorRedirectCode << kImm16Shift); // Read one particular bit out of the instruction bits. diff --git a/runtime/vm/constants_ia32.h b/runtime/vm/constants_ia32.h index 2c4a606b017..e80c2bbbace 100644 --- a/runtime/vm/constants_ia32.h +++ b/runtime/vm/constants_ia32.h @@ -107,17 +107,18 @@ const Register kWriteBarrierSlotReg = EDI; // Common ABI for shared slow path stubs. struct SharedSlowPathStubABI { - static const Register kResultReg = EAX; + static constexpr Register kResultReg = EAX; }; // ABI for instantiation stubs. struct InstantiationABI { - static const Register kUninstantiatedTypeArgumentsReg = EBX; - static const Register kInstantiatorTypeArgumentsReg = EDX; - static const Register kFunctionTypeArgumentsReg = ECX; - static const Register kResultTypeArgumentsReg = EAX; - static const Register kResultTypeReg = EAX; - static const Register kScratchReg = EDI; // On ia32 we don't use CODE_REG. + static constexpr Register kUninstantiatedTypeArgumentsReg = EBX; + static constexpr Register kInstantiatorTypeArgumentsReg = EDX; + static constexpr Register kFunctionTypeArgumentsReg = ECX; + static constexpr Register kResultTypeArgumentsReg = EAX; + static constexpr Register kResultTypeReg = EAX; + static constexpr Register kScratchReg = + EDI; // On ia32 we don't use CODE_REG. }; // Registers in addition to those listed in InstantiationABI used inside the @@ -125,7 +126,7 @@ struct InstantiationABI { struct InstantiateTAVInternalRegs { // On IA32, we don't do hash cache checks in the stub. We only define // kSavedRegisters to avoid needing to #ifdef uses of it. - static const intptr_t kSavedRegisters = 0; + static constexpr intptr_t kSavedRegisters = 0; }; // Calling convention when calling SubtypeTestCacheStub. @@ -133,17 +134,17 @@ struct InstantiateTAVInternalRegs { // 'TypeTestABI' name for symmetry with other architectures with a proper ABI. // Note that ia32 has no support for type testing stubs. struct TypeTestABI { - static const Register kInstanceReg = EAX; - static const Register kDstTypeReg = EBX; - static const Register kInstantiatorTypeArgumentsReg = EDX; - static const Register kFunctionTypeArgumentsReg = ECX; - static const Register kSubtypeTestCacheReg = + static constexpr Register kInstanceReg = EAX; + static constexpr Register kDstTypeReg = EBX; + static constexpr Register kInstantiatorTypeArgumentsReg = EDX; + static constexpr Register kFunctionTypeArgumentsReg = ECX; + static constexpr Register kSubtypeTestCacheReg = EDI; // On ia32 we don't use CODE_REG. // For call to InstanceOfStub. - static const Register kInstanceOfResultReg = kInstanceReg; + static constexpr Register kInstanceOfResultReg = kInstanceReg; // For call to SubtypeNTestCacheStub. - static const Register kSubtypeTestCacheResultReg = + static constexpr Register kSubtypeTestCacheResultReg = TypeTestABI::kSubtypeTestCacheReg; }; @@ -151,11 +152,12 @@ struct TypeTestABI { // architectures. We don't generate a call to the AssertSubtypeStub because we // need CODE_REG to store a fifth argument. struct AssertSubtypeABI { - static const Register kSubTypeReg = EAX; - static const Register kSuperTypeReg = EBX; - static const Register kInstantiatorTypeArgumentsReg = EDX; - static const Register kFunctionTypeArgumentsReg = ECX; - static const Register kDstNameReg = EDI; /// On ia32 we don't use CODE_REG. + static constexpr Register kSubTypeReg = EAX; + static constexpr Register kSuperTypeReg = EBX; + static constexpr Register kInstantiatorTypeArgumentsReg = EDX; + static constexpr Register kFunctionTypeArgumentsReg = ECX; + static constexpr Register kDstNameReg = + EDI; /// On ia32 we don't use CODE_REG. // No result register, as AssertSubtype is only run for side effect // (throws if the subtype check fails). @@ -163,198 +165,198 @@ struct AssertSubtypeABI { // For calling the ia32-specific AssertAssignableStub struct AssertAssignableStubABI { - static const Register kDstNameReg = EBX; - static const Register kSubtypeTestReg = ECX; + static constexpr Register kDstNameReg = EBX; + static constexpr Register kSubtypeTestReg = ECX; - static const intptr_t kInstanceSlotFromFp = 2 + 3; - static const intptr_t kDstTypeSlotFromFp = 2 + 2; - static const intptr_t kInstantiatorTAVSlotFromFp = 2 + 1; - static const intptr_t kFunctionTAVSlotFromFp = 2 + 0; + static constexpr intptr_t kInstanceSlotFromFp = 2 + 3; + static constexpr intptr_t kDstTypeSlotFromFp = 2 + 2; + static constexpr intptr_t kInstantiatorTAVSlotFromFp = 2 + 1; + static constexpr intptr_t kFunctionTAVSlotFromFp = 2 + 0; }; // ABI for InitStaticFieldStub. struct InitStaticFieldABI { - static const Register kFieldReg = EDX; - static const Register kResultReg = EAX; + static constexpr Register kFieldReg = EDX; + static constexpr Register kResultReg = EAX; }; // Registers used inside the implementation of InitLateStaticFieldStub. struct InitLateStaticFieldInternalRegs { - static const Register kAddressReg = ECX; - static const Register kScratchReg = EDI; + static constexpr Register kAddressReg = ECX; + static constexpr Register kScratchReg = EDI; }; // ABI for InitInstanceFieldStub. struct InitInstanceFieldABI { - static const Register kInstanceReg = EBX; - static const Register kFieldReg = EDX; - static const Register kResultReg = EAX; + static constexpr Register kInstanceReg = EBX; + static constexpr Register kFieldReg = EDX; + static constexpr Register kResultReg = EAX; }; // Registers used inside the implementation of InitLateInstanceFieldStub. struct InitLateInstanceFieldInternalRegs { - static const Register kAddressReg = ECX; - static const Register kScratchReg = EDI; + static constexpr Register kAddressReg = ECX; + static constexpr Register kScratchReg = EDI; }; // ABI for LateInitializationError stubs. struct LateInitializationErrorABI { - static const Register kFieldReg = EDI; + static constexpr Register kFieldReg = EDI; }; // ABI for ThrowStub. struct ThrowABI { - static const Register kExceptionReg = EAX; + static constexpr Register kExceptionReg = EAX; }; // ABI for ReThrowStub. struct ReThrowABI { - static const Register kExceptionReg = EAX; - static const Register kStackTraceReg = EBX; + static constexpr Register kExceptionReg = EAX; + static constexpr Register kStackTraceReg = EBX; }; // ABI for AssertBooleanStub. struct AssertBooleanABI { - static const Register kObjectReg = EAX; + static constexpr Register kObjectReg = EAX; }; // ABI for RangeErrorStub. struct RangeErrorABI { - static const Register kLengthReg = EAX; - static const Register kIndexReg = EBX; + static constexpr Register kLengthReg = EAX; + static constexpr Register kIndexReg = EBX; }; // ABI for AllocateObjectStub. struct AllocateObjectABI { - static const Register kResultReg = EAX; - static const Register kTypeArgumentsReg = EDX; - static const Register kTagsReg = kNoRegister; // Not used. + static constexpr Register kResultReg = EAX; + static constexpr Register kTypeArgumentsReg = EDX; + static constexpr Register kTagsReg = kNoRegister; // Not used. }; // ABI for Allocate{Mint,Double,Float32x4,Float64x2}Stub. struct AllocateBoxABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kTempReg = EBX; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kTempReg = EBX; }; // ABI for AllocateClosureStub. struct AllocateClosureABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kFunctionReg = EBX; - static const Register kContextReg = ECX; - static const Register kScratchReg = EDX; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kFunctionReg = EBX; + static constexpr Register kContextReg = ECX; + static constexpr Register kScratchReg = EDX; }; // ABI for AllocateArrayStub. struct AllocateArrayABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kLengthReg = EDX; - static const Register kTypeArgumentsReg = ECX; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kLengthReg = EDX; + static constexpr Register kTypeArgumentsReg = ECX; }; // ABI for AllocateRecordStub. struct AllocateRecordABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kShapeReg = EDX; - static const Register kTemp1Reg = EBX; - static const Register kTemp2Reg = EDI; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kShapeReg = EDX; + static constexpr Register kTemp1Reg = EBX; + static constexpr Register kTemp2Reg = EDI; }; // ABI for AllocateSmallRecordStub (AllocateRecord2, AllocateRecord2Named, // AllocateRecord3, AllocateRecord3Named). struct AllocateSmallRecordABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kShapeReg = EBX; - static const Register kValue0Reg = ECX; - static const Register kValue1Reg = EDX; - static const Register kValue2Reg = kNoRegister; - static const Register kTempReg = EDI; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kShapeReg = EBX; + static constexpr Register kValue0Reg = ECX; + static constexpr Register kValue1Reg = EDX; + static constexpr Register kValue2Reg = kNoRegister; + static constexpr Register kTempReg = EDI; }; // ABI for AllocateTypedDataArrayStub. struct AllocateTypedDataArrayABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kLengthReg = kResultReg; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kLengthReg = kResultReg; }; // ABI for BoxDoubleStub. struct BoxDoubleStubABI { - static const FpuRegister kValueReg = XMM0; - static const Register kTempReg = EBX; - static const Register kResultReg = EAX; + static constexpr FpuRegister kValueReg = XMM0; + static constexpr Register kTempReg = EBX; + static constexpr Register kResultReg = EAX; }; // ABI for DoubleToIntegerStub. struct DoubleToIntegerStubABI { - static const FpuRegister kInputReg = XMM0; - static const Register kRecognizedKindReg = EAX; - static const Register kResultReg = EAX; + static constexpr FpuRegister kInputReg = XMM0; + static constexpr Register kRecognizedKindReg = EAX; + static constexpr Register kResultReg = EAX; }; // ABI for SuspendStub (AwaitStub, AwaitWithTypeCheckStub, YieldAsyncStarStub, // SuspendSyncStarAtStartStub, SuspendSyncStarAtYieldStub). struct SuspendStubABI { - static const Register kArgumentReg = EAX; - static const Register kTypeArgsReg = EDX; // Can be the same as kTempReg - static const Register kTempReg = EDX; - static const Register kFrameSizeReg = ECX; - static const Register kSuspendStateReg = EBX; - static const Register kFunctionDataReg = EDI; + static constexpr Register kArgumentReg = EAX; + static constexpr Register kTypeArgsReg = EDX; // Can be the same as kTempReg + static constexpr Register kTempReg = EDX; + static constexpr Register kFrameSizeReg = ECX; + static constexpr Register kSuspendStateReg = EBX; + static constexpr Register kFunctionDataReg = EDI; // Can reuse THR. - static const Register kSrcFrameReg = ESI; + static constexpr Register kSrcFrameReg = ESI; // Can reuse kFunctionDataReg. - static const Register kDstFrameReg = EDI; + static constexpr Register kDstFrameReg = EDI; // Number of bytes to skip after // suspend stub return address in order to resume. // IA32: mov esp, ebp; pop ebp; ret - static const intptr_t kResumePcDistance = 4; + static constexpr intptr_t kResumePcDistance = 4; }; // ABI for InitSuspendableFunctionStub (InitAsyncStub, InitAsyncStarStub, // InitSyncStarStub). struct InitSuspendableFunctionStubABI { - static const Register kTypeArgsReg = EAX; + static constexpr Register kTypeArgsReg = EAX; }; // ABI for ResumeStub struct ResumeStubABI { - static const Register kSuspendStateReg = EBX; - static const Register kTempReg = EDX; + static constexpr Register kSuspendStateReg = EBX; + static constexpr Register kTempReg = EDX; // Registers for the frame copying (the 1st part). - static const Register kFrameSizeReg = ECX; + static constexpr Register kFrameSizeReg = ECX; // Can reuse THR. - static const Register kSrcFrameReg = ESI; + static constexpr Register kSrcFrameReg = ESI; // Can reuse CODE_REG. - static const Register kDstFrameReg = EDI; + static constexpr Register kDstFrameReg = EDI; // Registers for control transfer. // (the 2nd part, can reuse registers from the 1st part) - static const Register kResumePcReg = ECX; + static constexpr Register kResumePcReg = ECX; // Can also reuse kSuspendStateReg but should not conflict with CODE_REG. - static const Register kExceptionReg = EAX; - static const Register kStackTraceReg = EBX; + static constexpr Register kExceptionReg = EAX; + static constexpr Register kStackTraceReg = EBX; }; // ABI for ReturnStub (ReturnAsyncStub, ReturnAsyncNotFutureStub, // ReturnAsyncStarStub). struct ReturnStubABI { - static const Register kSuspendStateReg = EBX; + static constexpr Register kSuspendStateReg = EBX; }; // ABI for AsyncExceptionHandlerStub. struct AsyncExceptionHandlerStubABI { - static const Register kSuspendStateReg = EBX; + static constexpr Register kSuspendStateReg = EBX; }; // ABI for CloneSuspendStateStub. struct CloneSuspendStateStubABI { - static const Register kSourceReg = EAX; - static const Register kDestinationReg = EBX; - static const Register kTempReg = EDX; - static const Register kFrameSizeReg = ECX; + static constexpr Register kSourceReg = EAX; + static constexpr Register kDestinationReg = EBX; + static constexpr Register kTempReg = EDX; + static constexpr Register kFrameSizeReg = ECX; // Can reuse THR. - static const Register kSrcFrameReg = ESI; - static const Register kDstFrameReg = EDI; + static constexpr Register kSrcFrameReg = ESI; + static constexpr Register kDstFrameReg = EDI; }; // ABI for DispatchTableNullErrorStub and consequently for all dispatch @@ -364,7 +366,7 @@ struct CloneSuspendStateStubABI { // Note: dispatch table calls are never actually generated on IA32, this // declaration is only added for completeness. struct DispatchTableNullErrorABI { - static const Register kClassIdReg = EAX; + static constexpr Register kClassIdReg = EAX; }; typedef uint32_t RegList; @@ -420,10 +422,10 @@ enum ScaleFactor { class Instr { public: - static const uint8_t kHltInstruction = 0xF4; + static constexpr uint8_t kHltInstruction = 0xF4; // We prefer not to use the int3 instruction since it conflicts with gdb. - static const uint8_t kBreakPointInstruction = kHltInstruction; - static const int kBreakPointInstructionSize = 1; + static constexpr uint8_t kBreakPointInstruction = kHltInstruction; + static constexpr int kBreakPointInstructionSize = 1; bool IsBreakPoint() { ASSERT(kBreakPointInstructionSize == 1); @@ -449,18 +451,18 @@ const int MAX_NOP_SIZE = 8; class CallingConventions { public: static const Register ArgumentRegisters[]; - static const intptr_t kArgumentRegisters = 0; - static const intptr_t kFpuArgumentRegisters = 0; - static const intptr_t kNumArgRegs = 0; - static const Register kPointerToReturnStructRegisterCall = kNoRegister; + static constexpr intptr_t kArgumentRegisters = 0; + static constexpr intptr_t kFpuArgumentRegisters = 0; + static constexpr intptr_t kNumArgRegs = 0; + static constexpr Register kPointerToReturnStructRegisterCall = kNoRegister; static const XmmRegister FpuArgumentRegisters[]; - static const intptr_t kXmmArgumentRegisters = 0; - static const intptr_t kNumFpuArgRegs = 0; + static constexpr intptr_t kXmmArgumentRegisters = 0; + static constexpr intptr_t kNumFpuArgRegs = 0; static constexpr intptr_t kCalleeSaveCpuRegisters = kAbiPreservedCpuRegs; - static const bool kArgumentIntRegXorFpuReg = false; + static constexpr bool kArgumentIntRegXorFpuReg = false; static constexpr Register kReturnReg = EAX; static constexpr Register kSecondReturnReg = EDX; @@ -470,9 +472,9 @@ class CallingConventions { // return values. // See: https://c9x.me/x86/html/file_module_x86_id_280.html #if defined(_WIN32) - static const bool kUsesRet4 = false; + static constexpr bool kUsesRet4 = false; #else - static const bool kUsesRet4 = true; + static constexpr bool kUsesRet4 = true; #endif // Floating point values are returned on the "FPU stack" (in "ST" registers). diff --git a/runtime/vm/constants_riscv.h b/runtime/vm/constants_riscv.h index ca4361f69cf..57621fa39c3 100644 --- a/runtime/vm/constants_riscv.h +++ b/runtime/vm/constants_riscv.h @@ -195,13 +195,13 @@ struct InstantiationABI { struct InstantiateTAVInternalRegs { // The set of registers that must be pushed/popped when probing a hash-based // cache due to overlap with the registers in InstantiationABI. - static const intptr_t kSavedRegisters = 0; + static constexpr intptr_t kSavedRegisters = 0; // Additional registers used to probe hash-based caches. - static const Register kEntryStartReg = S3; - static const Register kProbeMaskReg = S4; - static const Register kProbeDistanceReg = S5; - static const Register kCurrentEntryIndexReg = S6; + static constexpr Register kEntryStartReg = S3; + static constexpr Register kProbeMaskReg = S4; + static constexpr Register kProbeDistanceReg = S5; + static constexpr Register kCurrentEntryIndexReg = S6; }; // Registers in addition to those listed in TypeTestABI used inside the @@ -216,7 +216,7 @@ struct TTSInternalRegs { // they overlap with registers in TypeTestABI. static constexpr intptr_t kSavedTypeArgumentRegisters = 0; - static const intptr_t kInternalRegisters = + static constexpr intptr_t kInternalRegisters = ((1 << kInstanceTypeArgumentsReg) | (1 << kScratchReg) | (1 << kSubTypeArgumentReg) | (1 << kSuperTypeArgumentReg)) & ~kSavedTypeArgumentRegisters; @@ -230,7 +230,7 @@ struct STCInternalRegs { static constexpr Register kInstanceParentFunctionTypeArgumentsReg = S5; static constexpr Register kInstanceDelayedFunctionTypeArgumentsReg = S6; - static const intptr_t kInternalRegisters = + static constexpr intptr_t kInternalRegisters = (1 << kInstanceCidOrSignatureReg) | (1 << kInstanceInstantiatorTypeArgumentsReg) | (1 << kInstanceParentFunctionTypeArgumentsReg) | @@ -253,19 +253,19 @@ struct TypeTestABI { static constexpr Register kSubtypeTestCacheResultReg = T0; // Registers that need saving across SubtypeTestCacheStub calls. - static const intptr_t kSubtypeTestCacheStubCallerSavedRegisters = + static constexpr intptr_t kSubtypeTestCacheStubCallerSavedRegisters = 1 << kSubtypeTestCacheReg; - static const intptr_t kPreservedAbiRegisters = + static constexpr intptr_t kPreservedAbiRegisters = (1 << kInstanceReg) | (1 << kDstTypeReg) | (1 << kInstantiatorTypeArgumentsReg) | (1 << kFunctionTypeArgumentsReg); - static const intptr_t kNonPreservedAbiRegisters = + static constexpr intptr_t kNonPreservedAbiRegisters = TTSInternalRegs::kInternalRegisters | STCInternalRegs::kInternalRegisters | (1 << kSubtypeTestCacheReg) | (1 << kScratchReg) | (1 << kSubtypeTestCacheResultReg) | (1 << CODE_REG); - static const intptr_t kAbiRegisters = + static constexpr intptr_t kAbiRegisters = kPreservedAbiRegisters | kNonPreservedAbiRegisters; }; @@ -277,7 +277,7 @@ struct AssertSubtypeABI { static constexpr Register kFunctionTypeArgumentsReg = T4; static constexpr Register kDstNameReg = T5; - static const intptr_t kAbiRegisters = + static constexpr intptr_t kAbiRegisters = (1 << kSubTypeReg) | (1 << kSuperTypeReg) | (1 << kInstantiatorTypeArgumentsReg) | (1 << kFunctionTypeArgumentsReg) | (1 << kDstNameReg); @@ -294,8 +294,8 @@ struct InitStaticFieldABI { // Registers used inside the implementation of InitLateStaticFieldStub. struct InitLateStaticFieldInternalRegs { - static const Register kAddressReg = T3; - static const Register kScratchReg = T4; + static constexpr Register kAddressReg = T3; + static constexpr Register kScratchReg = T4; }; // ABI for InitInstanceFieldStub. @@ -374,21 +374,21 @@ struct AllocateArrayABI { // ABI for AllocateRecordStub. struct AllocateRecordABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kShapeReg = T1; - static const Register kTemp1Reg = T2; - static const Register kTemp2Reg = T3; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kShapeReg = T1; + static constexpr Register kTemp1Reg = T2; + static constexpr Register kTemp2Reg = T3; }; // ABI for AllocateSmallRecordStub (AllocateRecord2, AllocateRecord2Named, // AllocateRecord3, AllocateRecord3Named). struct AllocateSmallRecordABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kShapeReg = T2; - static const Register kValue0Reg = T3; - static const Register kValue1Reg = T4; - static const Register kValue2Reg = A1; - static const Register kTempReg = T1; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kShapeReg = T2; + static constexpr Register kValue0Reg = T3; + static constexpr Register kValue1Reg = T4; + static constexpr Register kValue2Reg = A1; + static constexpr Register kTempReg = T1; }; // ABI for AllocateTypedDataArrayStub. @@ -414,57 +414,57 @@ struct DoubleToIntegerStubABI { // ABI for SuspendStub (AwaitStub, AwaitWithTypeCheckStub, YieldAsyncStarStub, // SuspendSyncStarAtStartStub, SuspendSyncStarAtYieldStub). struct SuspendStubABI { - static const Register kArgumentReg = A0; - static const Register kTypeArgsReg = T0; // Can be the same as kTempReg - static const Register kTempReg = T0; - static const Register kFrameSizeReg = T1; - static const Register kSuspendStateReg = T2; - static const Register kFunctionDataReg = T3; - static const Register kSrcFrameReg = T4; - static const Register kDstFrameReg = T5; + static constexpr Register kArgumentReg = A0; + static constexpr Register kTypeArgsReg = T0; // Can be the same as kTempReg + static constexpr Register kTempReg = T0; + static constexpr Register kFrameSizeReg = T1; + static constexpr Register kSuspendStateReg = T2; + static constexpr Register kFunctionDataReg = T3; + static constexpr Register kSrcFrameReg = T4; + static constexpr Register kDstFrameReg = T5; }; // ABI for InitSuspendableFunctionStub (InitAsyncStub, InitAsyncStarStub, // InitSyncStarStub). struct InitSuspendableFunctionStubABI { - static const Register kTypeArgsReg = A0; + static constexpr Register kTypeArgsReg = A0; }; // ABI for ResumeStub struct ResumeStubABI { - static const Register kSuspendStateReg = T1; - static const Register kTempReg = T0; + static constexpr Register kSuspendStateReg = T1; + static constexpr Register kTempReg = T0; // Registers for the frame copying (the 1st part). - static const Register kFrameSizeReg = T2; - static const Register kSrcFrameReg = T3; - static const Register kDstFrameReg = T4; + static constexpr Register kFrameSizeReg = T2; + static constexpr Register kSrcFrameReg = T3; + static constexpr Register kDstFrameReg = T4; // Registers for control transfer. // (the 2nd part, can reuse registers from the 1st part) - static const Register kResumePcReg = T2; + static constexpr Register kResumePcReg = T2; // Can also reuse kSuspendStateReg but should not conflict with CODE_REG/PP. - static const Register kExceptionReg = T3; - static const Register kStackTraceReg = T4; + static constexpr Register kExceptionReg = T3; + static constexpr Register kStackTraceReg = T4; }; // ABI for ReturnStub (ReturnAsyncStub, ReturnAsyncNotFutureStub, // ReturnAsyncStarStub). struct ReturnStubABI { - static const Register kSuspendStateReg = T1; + static constexpr Register kSuspendStateReg = T1; }; // ABI for AsyncExceptionHandlerStub. struct AsyncExceptionHandlerStubABI { - static const Register kSuspendStateReg = T1; + static constexpr Register kSuspendStateReg = T1; }; // ABI for CloneSuspendStateStub. struct CloneSuspendStateStubABI { - static const Register kSourceReg = A0; - static const Register kDestinationReg = A1; - static const Register kTempReg = T0; - static const Register kFrameSizeReg = T1; - static const Register kSrcFrameReg = T2; - static const Register kDstFrameReg = T3; + static constexpr Register kSourceReg = A0; + static constexpr Register kDestinationReg = A1; + static constexpr Register kTempReg = T0; + static constexpr Register kFrameSizeReg = T1; + static constexpr Register kSrcFrameReg = T2; + static constexpr Register kDstFrameReg = T3; }; // ABI for DispatchTableNullErrorStub and consequently for all dispatch @@ -529,18 +529,18 @@ constexpr int kStoreBufferWrapperSize = 26; class CallingConventions { public: - static const intptr_t kArgumentRegisters = kAbiArgumentCpuRegs; + static constexpr intptr_t kArgumentRegisters = kAbiArgumentCpuRegs; static const Register ArgumentRegisters[]; - static const intptr_t kNumArgRegs = 8; - static const Register kPointerToReturnStructRegisterCall = A0; - static const Register kPointerToReturnStructRegisterReturn = A0; + static constexpr intptr_t kNumArgRegs = 8; + static constexpr Register kPointerToReturnStructRegisterCall = A0; + static constexpr Register kPointerToReturnStructRegisterReturn = A0; static const FpuRegister FpuArgumentRegisters[]; - static const intptr_t kFpuArgumentRegisters = + static constexpr intptr_t kFpuArgumentRegisters = R(FA0) | R(FA1) | R(FA2) | R(FA3) | R(FA4) | R(FA5) | R(FA6) | R(FA7); - static const intptr_t kNumFpuArgRegs = 8; + static constexpr intptr_t kNumFpuArgRegs = 8; - static const bool kArgumentIntRegXorFpuReg = false; + static constexpr bool kArgumentIntRegXorFpuReg = false; static constexpr intptr_t kCalleeSaveCpuRegisters = kAbiPreservedCpuRegs; @@ -1112,9 +1112,10 @@ class Instr { uint32_t csr() const { return encoding_ >> 20; } uint32_t zimm() const { return rs1(); } - static const uint32_t kBreakPointInstruction = 0; - static const uint32_t kInstrSize = 4; - static const uint32_t kSimulatorRedirectInstruction = ECALL << 20 | SYSTEM; + static constexpr uint32_t kBreakPointInstruction = 0; + static constexpr uint32_t kInstrSize = 4; + static constexpr uint32_t kSimulatorRedirectInstruction = + ECALL << 20 | SYSTEM; private: const uint32_t encoding_; @@ -1454,7 +1455,7 @@ class CInstr { explicit CInstr(uint16_t encoding) : encoding_(encoding) {} uint16_t encoding() const { return encoding_; } - static const uint32_t kInstrSize = 2; + static constexpr uint32_t kInstrSize = 2; size_t length() const { return kInstrSize; } COpcode opcode() const { return COpcode(encoding_ & C_OP_MASK); } diff --git a/runtime/vm/constants_x64.h b/runtime/vm/constants_x64.h index d1f7cc1a31e..2ae4ea4b5c0 100644 --- a/runtime/vm/constants_x64.h +++ b/runtime/vm/constants_x64.h @@ -142,17 +142,17 @@ const Register kWriteBarrierSlotReg = R13; // Common ABI for shared slow path stubs. struct SharedSlowPathStubABI { - static const Register kResultReg = RAX; + static constexpr Register kResultReg = RAX; }; // ABI for instantiation stubs. struct InstantiationABI { - static const Register kUninstantiatedTypeArgumentsReg = RBX; - static const Register kInstantiatorTypeArgumentsReg = RDX; - static const Register kFunctionTypeArgumentsReg = RCX; - static const Register kResultTypeArgumentsReg = RAX; - static const Register kResultTypeReg = RAX; - static const Register kScratchReg = R9; + static constexpr Register kUninstantiatedTypeArgumentsReg = RBX; + static constexpr Register kInstantiatorTypeArgumentsReg = RDX; + static constexpr Register kFunctionTypeArgumentsReg = RCX; + static constexpr Register kResultTypeArgumentsReg = RAX; + static constexpr Register kResultTypeReg = RAX; + static constexpr Register kScratchReg = R9; }; // Registers in addition to those listed in InstantiationABI used inside the @@ -160,28 +160,28 @@ struct InstantiationABI { struct InstantiateTAVInternalRegs { // The set of registers that must be pushed/popped when probing a hash-based // cache due to overlap with the registers in InstantiationABI. - static const intptr_t kSavedRegisters = 0; + static constexpr intptr_t kSavedRegisters = 0; // Additional registers used to probe hash-based caches. - static const Register kEntryStartReg = R10; - static const Register kProbeMaskReg = R13; - static const Register kProbeDistanceReg = R8; - static const Register kCurrentEntryIndexReg = RSI; + static constexpr Register kEntryStartReg = R10; + static constexpr Register kProbeMaskReg = R13; + static constexpr Register kProbeDistanceReg = R8; + static constexpr Register kCurrentEntryIndexReg = RSI; }; // Registers in addition to those listed in TypeTestABI used inside the // implementation of type testing stubs that are _not_ preserved. struct TTSInternalRegs { - static const Register kInstanceTypeArgumentsReg = RSI; - static const Register kScratchReg = R8; - static const Register kSubTypeArgumentReg = R10; - static const Register kSuperTypeArgumentReg = R13; + static constexpr Register kInstanceTypeArgumentsReg = RSI; + static constexpr Register kScratchReg = R8; + static constexpr Register kSubTypeArgumentReg = R10; + static constexpr Register kSuperTypeArgumentReg = R13; // Must be pushed/popped whenever generic type arguments are being checked as // they overlap with registers in TypeTestABI. - static const intptr_t kSavedTypeArgumentRegisters = 0; + static constexpr intptr_t kSavedTypeArgumentRegisters = 0; - static const intptr_t kInternalRegisters = + static constexpr intptr_t kInternalRegisters = ((1 << kInstanceTypeArgumentsReg) | (1 << kScratchReg) | (1 << kSubTypeArgumentReg) | (1 << kSuperTypeArgumentReg)) & ~kSavedTypeArgumentRegisters; @@ -190,55 +190,55 @@ struct TTSInternalRegs { // Registers in addition to those listed in TypeTestABI used inside the // implementation of subtype test cache stubs that are _not_ preserved. struct STCInternalRegs { - static const Register kCacheEntryReg = RDI; - static const Register kInstanceCidOrSignatureReg = R10; - static const Register kInstanceInstantiatorTypeArgumentsReg = R13; + static constexpr Register kCacheEntryReg = RDI; + static constexpr Register kInstanceCidOrSignatureReg = R10; + static constexpr Register kInstanceInstantiatorTypeArgumentsReg = R13; - static const intptr_t kInternalRegisters = + static constexpr intptr_t kInternalRegisters = (1 << kCacheEntryReg) | (1 << kInstanceCidOrSignatureReg) | (1 << kInstanceInstantiatorTypeArgumentsReg); }; // Calling convention when calling TypeTestingStub and SubtypeTestCacheStub. struct TypeTestABI { - static const Register kInstanceReg = RAX; - static const Register kDstTypeReg = RBX; - static const Register kInstantiatorTypeArgumentsReg = RDX; - static const Register kFunctionTypeArgumentsReg = RCX; - static const Register kSubtypeTestCacheReg = R9; - static const Register kScratchReg = RSI; + static constexpr Register kInstanceReg = RAX; + static constexpr Register kDstTypeReg = RBX; + static constexpr Register kInstantiatorTypeArgumentsReg = RDX; + static constexpr Register kFunctionTypeArgumentsReg = RCX; + static constexpr Register kSubtypeTestCacheReg = R9; + static constexpr Register kScratchReg = RSI; // For calls to InstanceOfStub. - static const Register kInstanceOfResultReg = kInstanceReg; + static constexpr Register kInstanceOfResultReg = kInstanceReg; // For calls to SubtypeNTestCacheStub. Must not overlap with any other // registers above, for it is also used internally as kNullReg in those stubs. - static const Register kSubtypeTestCacheResultReg = R8; + static constexpr Register kSubtypeTestCacheResultReg = R8; // No registers need saving across SubtypeTestCacheStub calls. - static const intptr_t kSubtypeTestCacheStubCallerSavedRegisters = 0; + static constexpr intptr_t kSubtypeTestCacheStubCallerSavedRegisters = 0; - static const intptr_t kPreservedAbiRegisters = + static constexpr intptr_t kPreservedAbiRegisters = (1 << kInstanceReg) | (1 << kDstTypeReg) | (1 << kInstantiatorTypeArgumentsReg) | (1 << kFunctionTypeArgumentsReg); - static const intptr_t kNonPreservedAbiRegisters = + static constexpr intptr_t kNonPreservedAbiRegisters = TTSInternalRegs::kInternalRegisters | STCInternalRegs::kInternalRegisters | (1 << kSubtypeTestCacheReg) | (1 << kScratchReg) | (1 << kSubtypeTestCacheResultReg) | (1 << CODE_REG); - static const intptr_t kAbiRegisters = + static constexpr intptr_t kAbiRegisters = kPreservedAbiRegisters | kNonPreservedAbiRegisters; }; // Calling convention when calling AssertSubtypeStub. struct AssertSubtypeABI { - static const Register kSubTypeReg = RAX; - static const Register kSuperTypeReg = RBX; - static const Register kInstantiatorTypeArgumentsReg = RDX; - static const Register kFunctionTypeArgumentsReg = RCX; - static const Register kDstNameReg = R9; + static constexpr Register kSubTypeReg = RAX; + static constexpr Register kSuperTypeReg = RBX; + static constexpr Register kInstantiatorTypeArgumentsReg = RDX; + static constexpr Register kFunctionTypeArgumentsReg = RCX; + static constexpr Register kDstNameReg = R9; - static const intptr_t kAbiRegisters = + static constexpr intptr_t kAbiRegisters = (1 << kSubTypeReg) | (1 << kSuperTypeReg) | (1 << kInstantiatorTypeArgumentsReg) | (1 << kFunctionTypeArgumentsReg) | (1 << kDstNameReg); @@ -249,188 +249,188 @@ struct AssertSubtypeABI { // ABI for InitStaticFieldStub. struct InitStaticFieldABI { - static const Register kFieldReg = RDX; - static const Register kResultReg = RAX; + static constexpr Register kFieldReg = RDX; + static constexpr Register kResultReg = RAX; }; // Registers used inside the implementation of InitLateStaticFieldStub. struct InitLateStaticFieldInternalRegs { - static const Register kAddressReg = RCX; - static const Register kScratchReg = RSI; + static constexpr Register kAddressReg = RCX; + static constexpr Register kScratchReg = RSI; }; // ABI for InitInstanceFieldStub. struct InitInstanceFieldABI { - static const Register kInstanceReg = RBX; - static const Register kFieldReg = RDX; - static const Register kResultReg = RAX; + static constexpr Register kInstanceReg = RBX; + static constexpr Register kFieldReg = RDX; + static constexpr Register kResultReg = RAX; }; // Registers used inside the implementation of InitLateInstanceFieldStub. struct InitLateInstanceFieldInternalRegs { - static const Register kAddressReg = RCX; - static const Register kScratchReg = RSI; + static constexpr Register kAddressReg = RCX; + static constexpr Register kScratchReg = RSI; }; // ABI for LateInitializationError stubs. struct LateInitializationErrorABI { - static const Register kFieldReg = RSI; + static constexpr Register kFieldReg = RSI; }; // ABI for ThrowStub. struct ThrowABI { - static const Register kExceptionReg = RAX; + static constexpr Register kExceptionReg = RAX; }; // ABI for ReThrowStub. struct ReThrowABI { - static const Register kExceptionReg = RAX; - static const Register kStackTraceReg = RBX; + static constexpr Register kExceptionReg = RAX; + static constexpr Register kStackTraceReg = RBX; }; // ABI for AssertBooleanStub. struct AssertBooleanABI { - static const Register kObjectReg = RAX; + static constexpr Register kObjectReg = RAX; }; // ABI for RangeErrorStub. struct RangeErrorABI { - static const Register kLengthReg = RAX; - static const Register kIndexReg = RBX; + static constexpr Register kLengthReg = RAX; + static constexpr Register kIndexReg = RBX; }; // ABI for AllocateObjectStub. struct AllocateObjectABI { - static const Register kResultReg = RAX; - static const Register kTypeArgumentsReg = RDX; - static const Register kTagsReg = R8; + static constexpr Register kResultReg = RAX; + static constexpr Register kTypeArgumentsReg = RDX; + static constexpr Register kTagsReg = R8; }; // ABI for AllocateClosureStub. struct AllocateClosureABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kFunctionReg = RBX; - static const Register kContextReg = RDX; - static const Register kScratchReg = R13; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kFunctionReg = RBX; + static constexpr Register kContextReg = RDX; + static constexpr Register kScratchReg = R13; }; // ABI for AllocateMintShared*Stub. struct AllocateMintABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kTempReg = RBX; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kTempReg = RBX; }; // ABI for Allocate{Mint,Double,Float32x4,Float64x2}Stub. struct AllocateBoxABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kTempReg = RBX; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kTempReg = RBX; }; // ABI for AllocateArrayStub. struct AllocateArrayABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kLengthReg = R10; - static const Register kTypeArgumentsReg = RBX; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kLengthReg = R10; + static constexpr Register kTypeArgumentsReg = RBX; }; // ABI for AllocateRecordStub. struct AllocateRecordABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kShapeReg = RBX; - static const Register kTemp1Reg = RDX; - static const Register kTemp2Reg = RCX; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kShapeReg = RBX; + static constexpr Register kTemp1Reg = RDX; + static constexpr Register kTemp2Reg = RCX; }; // ABI for AllocateSmallRecordStub (AllocateRecord2, AllocateRecord2Named, // AllocateRecord3, AllocateRecord3Named). struct AllocateSmallRecordABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kShapeReg = R10; - static const Register kValue0Reg = RBX; - static const Register kValue1Reg = RDX; - static const Register kValue2Reg = RCX; - static const Register kTempReg = RDI; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kShapeReg = R10; + static constexpr Register kValue0Reg = RBX; + static constexpr Register kValue1Reg = RDX; + static constexpr Register kValue2Reg = RCX; + static constexpr Register kTempReg = RDI; }; // ABI for AllocateTypedDataArrayStub. struct AllocateTypedDataArrayABI { - static const Register kResultReg = AllocateObjectABI::kResultReg; - static const Register kLengthReg = kResultReg; + static constexpr Register kResultReg = AllocateObjectABI::kResultReg; + static constexpr Register kLengthReg = kResultReg; }; // ABI for BoxDoubleStub. struct BoxDoubleStubABI { - static const FpuRegister kValueReg = XMM0; - static const Register kTempReg = RBX; - static const Register kResultReg = RAX; + static constexpr FpuRegister kValueReg = XMM0; + static constexpr Register kTempReg = RBX; + static constexpr Register kResultReg = RAX; }; // ABI for DoubleToIntegerStub. struct DoubleToIntegerStubABI { - static const FpuRegister kInputReg = XMM0; - static const Register kRecognizedKindReg = RAX; - static const Register kResultReg = RAX; + static constexpr FpuRegister kInputReg = XMM0; + static constexpr Register kRecognizedKindReg = RAX; + static constexpr Register kResultReg = RAX; }; // ABI for SuspendStub (AwaitStub, AwaitWithTypeCheckStub, YieldAsyncStarStub, // SuspendSyncStarAtStartStub, SuspendSyncStarAtYieldStub). struct SuspendStubABI { - static const Register kArgumentReg = RAX; - static const Register kTypeArgsReg = RDX; // Can be the same as kTempReg - static const Register kTempReg = RDX; - static const Register kFrameSizeReg = RCX; - static const Register kSuspendStateReg = RBX; - static const Register kFunctionDataReg = R8; - static const Register kSrcFrameReg = RSI; - static const Register kDstFrameReg = RDI; + static constexpr Register kArgumentReg = RAX; + static constexpr Register kTypeArgsReg = RDX; // Can be the same as kTempReg + static constexpr Register kTempReg = RDX; + static constexpr Register kFrameSizeReg = RCX; + static constexpr Register kSuspendStateReg = RBX; + static constexpr Register kFunctionDataReg = R8; + static constexpr Register kSrcFrameReg = RSI; + static constexpr Register kDstFrameReg = RDI; // Number of bytes to skip after // suspend stub return address in order to resume. // X64: mov rsp, rbp; pop rbp; ret - static const intptr_t kResumePcDistance = 5; + static constexpr intptr_t kResumePcDistance = 5; }; // ABI for InitSuspendableFunctionStub (InitAsyncStub, InitAsyncStarStub, // InitSyncStarStub). struct InitSuspendableFunctionStubABI { - static const Register kTypeArgsReg = RAX; + static constexpr Register kTypeArgsReg = RAX; }; // ABI for ResumeStub struct ResumeStubABI { - static const Register kSuspendStateReg = RBX; - static const Register kTempReg = RDX; + static constexpr Register kSuspendStateReg = RBX; + static constexpr Register kTempReg = RDX; // Registers for the frame copying (the 1st part). - static const Register kFrameSizeReg = RCX; - static const Register kSrcFrameReg = RSI; - static const Register kDstFrameReg = RDI; + static constexpr Register kFrameSizeReg = RCX; + static constexpr Register kSrcFrameReg = RSI; + static constexpr Register kDstFrameReg = RDI; // Registers for control transfer. // (the 2nd part, can reuse registers from the 1st part) - static const Register kResumePcReg = RCX; + static constexpr Register kResumePcReg = RCX; // Can also reuse kSuspendStateReg but should not conflict with CODE_REG/PP. - static const Register kExceptionReg = RSI; - static const Register kStackTraceReg = RDI; + static constexpr Register kExceptionReg = RSI; + static constexpr Register kStackTraceReg = RDI; }; // ABI for ReturnStub (ReturnAsyncStub, ReturnAsyncNotFutureStub, // ReturnAsyncStarStub). struct ReturnStubABI { - static const Register kSuspendStateReg = RBX; + static constexpr Register kSuspendStateReg = RBX; }; // ABI for AsyncExceptionHandlerStub. struct AsyncExceptionHandlerStubABI { - static const Register kSuspendStateReg = RBX; + static constexpr Register kSuspendStateReg = RBX; }; // ABI for CloneSuspendStateStub. struct CloneSuspendStateStubABI { - static const Register kSourceReg = RAX; - static const Register kDestinationReg = RBX; - static const Register kTempReg = RDX; - static const Register kFrameSizeReg = RCX; - static const Register kSrcFrameReg = RSI; - static const Register kDstFrameReg = RDI; + static constexpr Register kSourceReg = RAX; + static constexpr Register kDestinationReg = RBX; + static constexpr Register kTempReg = RDX; + static constexpr Register kFrameSizeReg = RCX; + static constexpr Register kSrcFrameReg = RSI; + static constexpr Register kDstFrameReg = RDI; }; // ABI for DispatchTableNullErrorStub and consequently for all dispatch @@ -438,7 +438,7 @@ struct CloneSuspendStateStubABI { // register). This ABI is added to distinguish memory corruption errors from // null errors. struct DispatchTableNullErrorABI { - static const Register kClassIdReg = RCX; + static constexpr Register kClassIdReg = RCX; }; typedef uint32_t RegList; @@ -505,27 +505,27 @@ enum ScaleFactor { class CallingConventions { public: #if defined(DART_TARGET_OS_WINDOWS) - static const Register kArg1Reg = RCX; - static const Register kArg2Reg = RDX; - static const Register kArg3Reg = R8; - static const Register kArg4Reg = R9; + static constexpr Register kArg1Reg = RCX; + static constexpr Register kArg2Reg = RDX; + static constexpr Register kArg3Reg = R8; + static constexpr Register kArg4Reg = R9; static const Register ArgumentRegisters[]; - static const intptr_t kArgumentRegisters = + static constexpr intptr_t kArgumentRegisters = R(kArg1Reg) | R(kArg2Reg) | R(kArg3Reg) | R(kArg4Reg); - static const intptr_t kNumArgRegs = 4; - static const Register kPointerToReturnStructRegisterCall = kArg1Reg; + static constexpr intptr_t kNumArgRegs = 4; + static constexpr Register kPointerToReturnStructRegisterCall = kArg1Reg; static const XmmRegister FpuArgumentRegisters[]; - static const intptr_t kFpuArgumentRegisters = + static constexpr intptr_t kFpuArgumentRegisters = R(XMM0) | R(XMM1) | R(XMM2) | R(XMM3); - static const intptr_t kNumFpuArgRegs = 4; + static constexpr intptr_t kNumFpuArgRegs = 4; // Whether ArgumentRegisters[i] prevents using XmmArgumentRegisters[i] at the // same time and vice versa. - static const bool kArgumentIntRegXorFpuReg = true; + static constexpr bool kArgumentIntRegXorFpuReg = true; // AL not set on vararg calls in Windows. - static const Register kVarArgFpuRegisterCount = kNoRegister; + static constexpr Register kVarArgFpuRegisterCount = kNoRegister; // > The x64 Application Binary Interface (ABI) uses a four-register // > fast-call calling convention by default. Space is allocated on the call @@ -537,18 +537,18 @@ class CallingConventions { // // This is also known as home space. // https://devblogs.microsoft.com/oldnewthing/20160623-00/?p=93735 - static const intptr_t kShadowSpaceBytes = 4 * kWordSize; + static constexpr intptr_t kShadowSpaceBytes = 4 * kWordSize; - static const intptr_t kVolatileCpuRegisters = + static constexpr intptr_t kVolatileCpuRegisters = R(RAX) | R(RCX) | R(RDX) | R(R8) | R(R9) | R(R10) | R(R11); - static const RegList kVolatileXmmRegisters = kAbiVolatileFpuRegs; + static constexpr RegList kVolatileXmmRegisters = kAbiVolatileFpuRegs; - static const intptr_t kCalleeSaveXmmRegisters = + static constexpr intptr_t kCalleeSaveXmmRegisters = R(XMM6) | R(XMM7) | R(XMM8) | R(XMM9) | R(XMM10) | R(XMM11) | R(XMM12) | R(XMM13) | R(XMM14) | R(XMM15); - static const XmmRegister xmmFirstNonParameterReg = XMM4; + static constexpr XmmRegister xmmFirstNonParameterReg = XMM4; // Windows x64 ABI specifies that small objects are passed in registers. // Otherwise they are passed by reference. @@ -579,28 +579,28 @@ class CallingConventions { static constexpr ExtensionStrategy kArgumentStackExtension = kNotExtended; #else - static const Register kArg1Reg = RDI; - static const Register kArg2Reg = RSI; - static const Register kArg3Reg = RDX; - static const Register kArg4Reg = RCX; - static const Register kArg5Reg = R8; - static const Register kArg6Reg = R9; + static constexpr Register kArg1Reg = RDI; + static constexpr Register kArg2Reg = RSI; + static constexpr Register kArg3Reg = RDX; + static constexpr Register kArg4Reg = RCX; + static constexpr Register kArg5Reg = R8; + static constexpr Register kArg6Reg = R9; static const Register ArgumentRegisters[]; - static const intptr_t kArgumentRegisters = R(kArg1Reg) | R(kArg2Reg) | - R(kArg3Reg) | R(kArg4Reg) | - R(kArg5Reg) | R(kArg6Reg); - static const intptr_t kNumArgRegs = 6; - static const Register kPointerToReturnStructRegisterCall = kArg1Reg; + static constexpr intptr_t kArgumentRegisters = R(kArg1Reg) | R(kArg2Reg) | + R(kArg3Reg) | R(kArg4Reg) | + R(kArg5Reg) | R(kArg6Reg); + static constexpr intptr_t kNumArgRegs = 6; + static constexpr Register kPointerToReturnStructRegisterCall = kArg1Reg; static const XmmRegister FpuArgumentRegisters[]; - static const intptr_t kFpuArgumentRegisters = R(XMM0) | R(XMM1) | R(XMM2) | - R(XMM3) | R(XMM4) | R(XMM5) | - R(XMM6) | R(XMM7); - static const intptr_t kNumFpuArgRegs = 8; + static constexpr intptr_t kFpuArgumentRegisters = + R(XMM0) | R(XMM1) | R(XMM2) | R(XMM3) | R(XMM4) | R(XMM5) | R(XMM6) | + R(XMM7); + static constexpr intptr_t kNumFpuArgRegs = 8; // Whether ArgumentRegisters[i] prevents using XmmArgumentRegisters[i] at the // same time and vice versa. - static const bool kArgumentIntRegXorFpuReg = false; + static constexpr bool kArgumentIntRegXorFpuReg = false; // > For calls that may call functions that use varargs or stdargs // > (prototype-less calls or calls to functions containing ellipsis (...) in @@ -609,19 +609,19 @@ class CallingConventions { // > exactly the number of registers, but must be an upper bound on the number // > of vector registers used and is in the range 0–8 inclusive. // System V ABI spec. - static const Register kVarArgFpuRegisterCount = RAX; + static constexpr Register kVarArgFpuRegisterCount = RAX; - static const intptr_t kShadowSpaceBytes = 0; + static constexpr intptr_t kShadowSpaceBytes = 0; - static const intptr_t kVolatileCpuRegisters = R(RAX) | R(RCX) | R(RDX) | - R(RSI) | R(RDI) | R(R8) | - R(R9) | R(R10) | R(R11); + static constexpr intptr_t kVolatileCpuRegisters = R(RAX) | R(RCX) | R(RDX) | + R(RSI) | R(RDI) | R(R8) | + R(R9) | R(R10) | R(R11); - static const RegList kVolatileXmmRegisters = kAbiVolatileFpuRegs; + static constexpr RegList kVolatileXmmRegisters = kAbiVolatileFpuRegs; - static const intptr_t kCalleeSaveXmmRegisters = 0; + static constexpr intptr_t kCalleeSaveXmmRegisters = 0; - static const XmmRegister xmmFirstNonParameterReg = XMM8; + static constexpr XmmRegister xmmFirstNonParameterReg = XMM8; static constexpr Register kReturnReg = RAX; static constexpr Register kSecondReturnReg = RDX; @@ -653,7 +653,7 @@ class CallingConventions { #endif - static const intptr_t kCalleeSaveCpuRegisters = kAbiPreservedCpuRegs; + static constexpr intptr_t kCalleeSaveCpuRegisters = kAbiPreservedCpuRegs; COMPILE_ASSERT((kArgumentRegisters & kReservedCpuRegisters) == 0); @@ -673,11 +673,11 @@ class CallingConventions { class Instr { public: - static const uint8_t kHltInstruction = 0xF4; + static constexpr uint8_t kHltInstruction = 0xF4; // We prefer not to use the int3 instruction since it conflicts with gdb. - static const uint8_t kBreakPointInstruction = kHltInstruction; - static const int kBreakPointInstructionSize = 1; - static const uint8_t kGdbBreakpointInstruction = 0xcc; + static constexpr uint8_t kBreakPointInstruction = kHltInstruction; + static constexpr int kBreakPointInstructionSize = 1; + static constexpr uint8_t kGdbBreakpointInstruction = 0xcc; bool IsBreakPoint() { ASSERT(kBreakPointInstructionSize == 1); diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc index de09fde56cb..0718869d4f3 100644 --- a/runtime/vm/dart_api_impl.cc +++ b/runtime/vm/dart_api_impl.cc @@ -4135,7 +4135,7 @@ class AcquiredData { } private: - static const uint8_t kZapReleasedByte = 0xda; + static constexpr uint8_t kZapReleasedByte = 0xda; intptr_t size_in_bytes_; void* data_; void* data_copy_; @@ -6547,9 +6547,9 @@ DART_EXPORT Dart_Handle Dart_Precompile() { // Used for StreamingWriteStream/BlobImageWriter sizes for ELF and blobs. #if !defined(TARGET_ARCH_IA32) && defined(DART_PRECOMPILER) -static const intptr_t kAssemblyInitialSize = 512 * KB; -static const intptr_t kInitialSize = 2 * MB; -static const intptr_t kInitialDebugSize = 1 * MB; +static constexpr intptr_t kAssemblyInitialSize = 512 * KB; +static constexpr intptr_t kInitialSize = 2 * MB; +static constexpr intptr_t kInitialDebugSize = 1 * MB; static void CreateAppAOTSnapshot( Dart_StreamingWriteCallback callback, diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc index 9baad7685ed..e9911d036ba 100644 --- a/runtime/vm/dart_api_impl_test.cc +++ b/runtime/vm/dart_api_impl_test.cc @@ -1801,12 +1801,12 @@ TEST_CASE(DartAPI_ExternalStringPretenure) { TEST_CASE(DartAPI_ExternalTypedDataPretenure) { { Dart_EnterScope(); - static const int kBigLength = 16 * MB / 8; + const int kBigLength = 16 * MB / 8; int64_t* big_data = new int64_t[kBigLength](); Dart_Handle big = Dart_NewExternalTypedData(Dart_TypedData_kInt64, big_data, kBigLength); EXPECT_VALID(big); - static const int kSmallLength = 16 * KB / 8; + const int kSmallLength = 16 * KB / 8; int64_t* small_data = new int64_t[kSmallLength](); Dart_Handle small = Dart_NewExternalTypedData(Dart_TypedData_kInt64, small_data, kSmallLength); @@ -2344,7 +2344,7 @@ ByteData main() { EXPECT_VALID(result); } -static const intptr_t kExtLength = 16; +static constexpr intptr_t kExtLength = 16; static int8_t data[kExtLength] = { 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42, @@ -2483,7 +2483,7 @@ TEST_CASE(DartAPI_ExternalByteDataFinalizer) { #ifndef PRODUCT -static const intptr_t kOptExtLength = 16; +static constexpr intptr_t kOptExtLength = 16; static int8_t opt_data[kOptExtLength] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, @@ -4188,7 +4188,7 @@ TEST_CASE(DartAPI_WeakPersistentHandleExternalAllocationSize) { EXPECT(heap->ExternalInWords(Heap::kNew) == 0); EXPECT(heap->ExternalInWords(Heap::kOld) == 0); Dart_WeakPersistentHandle weak1 = nullptr; - static const intptr_t kWeak1ExternalSize = 1 * KB; + const intptr_t kWeak1ExternalSize = 1 * KB; { Dart_EnterScope(); Dart_Handle obj = NewString("weakly referenced string"); @@ -4200,7 +4200,7 @@ TEST_CASE(DartAPI_WeakPersistentHandleExternalAllocationSize) { } Dart_PersistentHandle strong_ref = nullptr; Dart_WeakPersistentHandle weak2 = nullptr; - static const intptr_t kWeak2ExternalSize = 2 * KB; + const intptr_t kWeak2ExternalSize = 2 * KB; { Dart_EnterScope(); Dart_Handle obj = NewString("strongly referenced string"); @@ -4237,7 +4237,7 @@ TEST_CASE(DartAPI_FinalizableHandleExternalAllocationSize) { Heap* heap = IsolateGroup::Current()->heap(); EXPECT(heap->ExternalInWords(Heap::kNew) == 0); EXPECT(heap->ExternalInWords(Heap::kOld) == 0); - static const intptr_t kWeak1ExternalSize = 1 * KB; + const intptr_t kWeak1ExternalSize = 1 * KB; { Dart_EnterScope(); Dart_Handle obj = NewString("weakly referenced string"); @@ -4246,7 +4246,7 @@ TEST_CASE(DartAPI_FinalizableHandleExternalAllocationSize) { Dart_ExitScope(); } Dart_PersistentHandle strong_ref = nullptr; - static const intptr_t kWeak2ExternalSize = 2 * KB; + const intptr_t kWeak2ExternalSize = 2 * KB; { Dart_EnterScope(); Dart_Handle obj = NewString("strongly referenced string"); @@ -4443,9 +4443,9 @@ TEST_CASE(DartAPI_FinalizableHandleExternalAllocationSizeOldspaceGC) { TEST_CASE(DartAPI_WeakPersistentHandleExternalAllocationSizeOddReferents) { Heap* heap = IsolateGroup::Current()->heap(); Dart_WeakPersistentHandle weak1 = nullptr; - static const intptr_t kWeak1ExternalSize = 1 * KB; + const intptr_t kWeak1ExternalSize = 1 * KB; Dart_WeakPersistentHandle weak2 = nullptr; - static const intptr_t kWeak2ExternalSize = 2 * KB; + const intptr_t kWeak2ExternalSize = 2 * KB; EXPECT_EQ(0, heap->ExternalInWords(Heap::kOld)); { Dart_EnterScope(); @@ -4478,10 +4478,10 @@ TEST_CASE(DartAPI_FinalizableHandleExternalAllocationSizeOddReferents) { Heap* heap = IsolateGroup::Current()->heap(); Dart_FinalizableHandle weak1 = nullptr; Dart_PersistentHandle strong1 = nullptr; - static const intptr_t kWeak1ExternalSize = 1 * KB; + const intptr_t kWeak1ExternalSize = 1 * KB; Dart_FinalizableHandle weak2 = nullptr; Dart_PersistentHandle strong2 = nullptr; - static const intptr_t kWeak2ExternalSize = 2 * KB; + const intptr_t kWeak2ExternalSize = 2 * KB; EXPECT_EQ(0, heap->ExternalInWords(Heap::kOld)); { Dart_EnterScope(); @@ -5787,9 +5787,9 @@ TEST_CASE(DartAPI_InjectNativeFields4) { #endif } -static const int kTestNumNativeFields = 2; -static const intptr_t kNativeField1Value = 30; -static const intptr_t kNativeField2Value = 40; +static constexpr int kTestNumNativeFields = 2; +static constexpr intptr_t kNativeField1Value = 30; +static constexpr intptr_t kNativeField2Value = 40; void TestNativeFieldsAccess_init(Dart_NativeArguments args) { Dart_Handle receiver = Dart_GetNativeArgument(args, 0); @@ -8457,7 +8457,7 @@ TEST_CASE(DartAPI_NativePortPostTransferrableTypedData) { EXPECT(Dart_CloseNativePort(port_id2)); } -static const intptr_t kSendLength = 16; +static constexpr intptr_t kSendLength = 16; static void NewNativePort_ExternalTypedData(Dart_Port dest_port_id, Dart_CObject* message) { diff --git a/runtime/vm/dart_api_state.h b/runtime/vm/dart_api_state.h index e49a99cef19..71ecf6bc739 100644 --- a/runtime/vm/dart_api_state.h +++ b/runtime/vm/dart_api_state.h @@ -372,9 +372,9 @@ class FinalizablePersistentHandle { }; // Local handles repository structure. -static const int kLocalHandleSizeInWords = sizeof(LocalHandle) / kWordSize; -static const int kLocalHandlesPerChunk = 64; -static const int kOffsetOfRawPtrInLocalHandle = 0; +static constexpr int kLocalHandleSizeInWords = sizeof(LocalHandle) / kWordSize; +static constexpr int kLocalHandlesPerChunk = 64; +static constexpr int kOffsetOfRawPtrInLocalHandle = 0; class LocalHandles : Handles { @@ -431,10 +431,10 @@ class LocalHandles : Handles { @@ -521,10 +521,10 @@ class PersistentHandles : Handles { }; class DeoptId @@ -580,7 +580,7 @@ class DeoptMintPairInstr : public DeoptIntegerInstrBase { } private: - static const intptr_t kFieldWidth = kBitsPerWord / 2; + static constexpr intptr_t kFieldWidth = kBitsPerWord / 2; class LoRegister : public BitField {}; class HiRegister : public BitField {}; diff --git a/runtime/vm/deopt_instructions.h b/runtime/vm/deopt_instructions.h index 0ee620f175d..e94d34557cd 100644 --- a/runtime/vm/deopt_instructions.h +++ b/runtime/vm/deopt_instructions.h @@ -571,7 +571,7 @@ class DeoptTable : public AllStatic { class FlagsField : public BitField {}; private: - static const intptr_t kEntrySize = 3; + static constexpr intptr_t kEntrySize = 3; }; // Holds deopt information at one deoptimization point. The information consists diff --git a/runtime/vm/double_conversion.cc b/runtime/vm/double_conversion.cc index 55b78361eba..84743daadec 100644 --- a/runtime/vm/double_conversion.cc +++ b/runtime/vm/double_conversion.cc @@ -12,13 +12,13 @@ namespace dart { -char const DoubleToStringConstants::kExponentChar = 'e'; -const char* const DoubleToStringConstants::kInfinitySymbol = "Infinity"; -const char* const DoubleToStringConstants::kNaNSymbol = "NaN"; +static constexpr char kExponentChar = 'e'; +static constexpr const char* kInfinitySymbol = "Infinity"; +static constexpr const char* kNaNSymbol = "NaN"; void DoubleToCString(double d, char* buffer, int buffer_size) { - static const int kDecimalLow = -6; - static const int kDecimalHigh = 21; + const int kDecimalLow = -6; + const int kDecimalHigh = 21; // The output contains the sign, at most kDecimalHigh - 1 digits, // the decimal point followed by a 0 plus the \0. @@ -31,16 +31,15 @@ void DoubleToCString(double d, char* buffer, int buffer_size) { // sign, at most three exponent digits, plus the \0. ASSERT(buffer_size >= 1 + 17 + 1 + 1 + 1 + 3 + 1); - static const int kConversionFlags = + const int kConversionFlags = double_conversion::DoubleToStringConverter::EMIT_POSITIVE_EXPONENT_SIGN | double_conversion::DoubleToStringConverter::EMIT_TRAILING_DECIMAL_POINT | double_conversion::DoubleToStringConverter:: EMIT_TRAILING_ZERO_AFTER_POINT; const double_conversion::DoubleToStringConverter converter( - kConversionFlags, DoubleToStringConstants::kInfinitySymbol, - DoubleToStringConstants::kNaNSymbol, - DoubleToStringConstants::kExponentChar, kDecimalLow, kDecimalHigh, 0, + kConversionFlags, kInfinitySymbol, kNaNSymbol, kExponentChar, kDecimalLow, + kDecimalHigh, 0, 0); // Last two values are ignored in shortest mode. double_conversion::StringBuilder builder(buffer, buffer_size); @@ -51,14 +50,14 @@ void DoubleToCString(double d, char* buffer, int buffer_size) { } StringPtr DoubleToStringAsFixed(double d, int fraction_digits) { - static const int kMinFractionDigits = 0; - static const int kMaxFractionDigits = 20; - static const int kMaxDigitsBeforePoint = 20; + const int kMinFractionDigits = 0; + const int kMaxFractionDigits = 20; + const int kMaxDigitsBeforePoint = 20; // The boundaries are exclusive. - static const double kLowerBoundary = -1e21; - static const double kUpperBoundary = 1e21; + const double kLowerBoundary = -1e21; + const double kUpperBoundary = 1e21; // TODO(floitsch): remove the UNIQUE_ZERO flag when the test is updated. - static const int kConversionFlags = + const int kConversionFlags = double_conversion::DoubleToStringConverter::NO_FLAGS; const int kBufferSize = 128; @@ -78,9 +77,7 @@ StringPtr DoubleToStringAsFixed(double d, int fraction_digits) { fraction_digits <= kMaxFractionDigits); const double_conversion::DoubleToStringConverter converter( - kConversionFlags, DoubleToStringConstants::kInfinitySymbol, - DoubleToStringConstants::kNaNSymbol, - DoubleToStringConstants::kExponentChar, 0, 0, 0, + kConversionFlags, kInfinitySymbol, kNaNSymbol, kExponentChar, 0, 0, 0, 0); // Last four values are ignored in fixed mode. char* buffer = Thread::Current()->zone()->Alloc(kBufferSize); @@ -92,9 +89,9 @@ StringPtr DoubleToStringAsFixed(double d, int fraction_digits) { } StringPtr DoubleToStringAsExponential(double d, int fraction_digits) { - static const int kMinFractionDigits = -1; // -1 represents shortest mode. - static const int kMaxFractionDigits = 20; - static const int kConversionFlags = + const int kMinFractionDigits = -1; // -1 represents shortest mode. + const int kMaxFractionDigits = 20; + const int kConversionFlags = double_conversion::DoubleToStringConverter::EMIT_POSITIVE_EXPONENT_SIGN; const int kBufferSize = 128; @@ -109,9 +106,7 @@ StringPtr DoubleToStringAsExponential(double d, int fraction_digits) { fraction_digits <= kMaxFractionDigits); const double_conversion::DoubleToStringConverter converter( - kConversionFlags, DoubleToStringConstants::kInfinitySymbol, - DoubleToStringConstants::kNaNSymbol, - DoubleToStringConstants::kExponentChar, 0, 0, 0, + kConversionFlags, kInfinitySymbol, kNaNSymbol, kExponentChar, 0, 0, 0, 0); // Last four values are ignored in exponential mode. char* buffer = Thread::Current()->zone()->Alloc(kBufferSize); @@ -123,11 +118,11 @@ StringPtr DoubleToStringAsExponential(double d, int fraction_digits) { } StringPtr DoubleToStringAsPrecision(double d, int precision) { - static const int kMinPrecisionDigits = 1; - static const int kMaxPrecisionDigits = 21; - static const int kMaxLeadingPaddingZeroes = 6; - static const int kMaxTrailingPaddingZeroes = 0; - static const int kConversionFlags = + const int kMinPrecisionDigits = 1; + const int kMaxPrecisionDigits = 21; + const int kMaxLeadingPaddingZeroes = 6; + const int kMaxTrailingPaddingZeroes = 0; + const int kConversionFlags = double_conversion::DoubleToStringConverter::EMIT_POSITIVE_EXPONENT_SIGN; const int kBufferSize = 128; @@ -145,9 +140,7 @@ StringPtr DoubleToStringAsPrecision(double d, int precision) { ASSERT(kMinPrecisionDigits <= precision && precision <= kMaxPrecisionDigits); const double_conversion::DoubleToStringConverter converter( - kConversionFlags, DoubleToStringConstants::kInfinitySymbol, - DoubleToStringConstants::kNaNSymbol, - DoubleToStringConstants::kExponentChar, 0, + kConversionFlags, kInfinitySymbol, kNaNSymbol, kExponentChar, 0, 0, // Ignored in precision mode. kMaxLeadingPaddingZeroes, kMaxTrailingPaddingZeroes); @@ -166,8 +159,7 @@ bool CStringToDouble(const char* str, intptr_t length, double* result) { double_conversion::StringToDoubleConverter converter( double_conversion::StringToDoubleConverter::NO_FLAGS, 0.0, 0.0, - DoubleToStringConstants::kInfinitySymbol, - DoubleToStringConstants::kNaNSymbol); + kInfinitySymbol, kNaNSymbol); int parsed_count = 0; *result = diff --git a/runtime/vm/double_conversion.h b/runtime/vm/double_conversion.h index 6fbe380357e..f02b4e930a0 100644 --- a/runtime/vm/double_conversion.h +++ b/runtime/vm/double_conversion.h @@ -11,12 +11,6 @@ namespace dart { -struct DoubleToStringConstants : AllStatic { - static char const kExponentChar; - static const char* const kInfinitySymbol; - static const char* const kNaNSymbol; -}; - void DoubleToCString(double d, char* buffer, int buffer_size); StringPtr DoubleToStringAsFixed(double d, int fraction_digits); StringPtr DoubleToStringAsExponential(double d, int fraction_digits); diff --git a/runtime/vm/double_internals.h b/runtime/vm/double_internals.h index 87125be35c5..b16cc248b87 100644 --- a/runtime/vm/double_internals.h +++ b/runtime/vm/double_internals.h @@ -17,7 +17,7 @@ static uint64_t double_to_uint64(double d) { // Helper functions for doubles. class DoubleInternals { public: - static const int kSignificandSize = 53; + static constexpr int kSignificandSize = 53; explicit DoubleInternals(double d) : d64_(double_to_uint64(d)) {} @@ -62,15 +62,18 @@ class DoubleInternals { } private: - static const uint64_t kSignMask = DART_2PART_UINT64_C(0x80000000, 00000000); - static const uint64_t kExponentMask = + static constexpr uint64_t kSignMask = + DART_2PART_UINT64_C(0x80000000, 00000000); + static constexpr uint64_t kExponentMask = DART_2PART_UINT64_C(0x7FF00000, 00000000); - static const uint64_t kSignificandMask = + static constexpr uint64_t kSignificandMask = DART_2PART_UINT64_C(0x000FFFFF, FFFFFFFF); - static const uint64_t kHiddenBit = DART_2PART_UINT64_C(0x00100000, 00000000); - static const int kPhysicalSignificandSize = 52; // Excludes the hidden bit. - static const int kExponentBias = 0x3FF + kPhysicalSignificandSize; - static const int kDenormalExponent = -kExponentBias + 1; + static constexpr uint64_t kHiddenBit = + DART_2PART_UINT64_C(0x00100000, 00000000); + static constexpr int kPhysicalSignificandSize = + 52; // Excludes the hidden bit. + static constexpr int kExponentBias = 0x3FF + kPhysicalSignificandSize; + static constexpr int kDenormalExponent = -kExponentBias + 1; const uint64_t d64_; }; diff --git a/runtime/vm/dwarf.h b/runtime/vm/dwarf.h index 91c677b41ff..683f9321ae0 100644 --- a/runtime/vm/dwarf.h +++ b/runtime/vm/dwarf.h @@ -177,7 +177,7 @@ class Trie : public ZoneAllocated { private: // Currently, only the following characters can appear in obfuscated names: // '_', '@', '0-9', 'a-z', 'A-Z' - static const intptr_t kNumValidChars = 64; + static constexpr intptr_t kNumValidChars = 64; Trie() { for (intptr_t i = 0; i < kNumValidChars; i++) { @@ -247,55 +247,55 @@ class Dwarf : public ZoneAllocated { private: friend class LineNumberProgramWriter; - static const intptr_t DW_TAG_compile_unit = 0x11; - static const intptr_t DW_TAG_inlined_subroutine = 0x1d; - static const intptr_t DW_TAG_subprogram = 0x2e; + static constexpr intptr_t DW_TAG_compile_unit = 0x11; + static constexpr intptr_t DW_TAG_inlined_subroutine = 0x1d; + static constexpr intptr_t DW_TAG_subprogram = 0x2e; - static const intptr_t DW_CHILDREN_no = 0x0; - static const intptr_t DW_CHILDREN_yes = 0x1; + static constexpr intptr_t DW_CHILDREN_no = 0x0; + static constexpr intptr_t DW_CHILDREN_yes = 0x1; - static const intptr_t DW_AT_sibling = 0x1; - static const intptr_t DW_AT_name = 0x3; - static const intptr_t DW_AT_stmt_list = 0x10; - static const intptr_t DW_AT_low_pc = 0x11; - static const intptr_t DW_AT_high_pc = 0x12; - static const intptr_t DW_AT_comp_dir = 0x1b; - static const intptr_t DW_AT_inline = 0x20; - static const intptr_t DW_AT_producer = 0x25; - static const intptr_t DW_AT_abstract_origin = 0x31; - static const intptr_t DW_AT_artificial = 0x34; - static const intptr_t DW_AT_decl_column = 0x39; - static const intptr_t DW_AT_decl_file = 0x3a; - static const intptr_t DW_AT_decl_line = 0x3b; - static const intptr_t DW_AT_call_column = 0x57; - static const intptr_t DW_AT_call_file = 0x58; - static const intptr_t DW_AT_call_line = 0x59; + static constexpr intptr_t DW_AT_sibling = 0x1; + static constexpr intptr_t DW_AT_name = 0x3; + static constexpr intptr_t DW_AT_stmt_list = 0x10; + static constexpr intptr_t DW_AT_low_pc = 0x11; + static constexpr intptr_t DW_AT_high_pc = 0x12; + static constexpr intptr_t DW_AT_comp_dir = 0x1b; + static constexpr intptr_t DW_AT_inline = 0x20; + static constexpr intptr_t DW_AT_producer = 0x25; + static constexpr intptr_t DW_AT_abstract_origin = 0x31; + static constexpr intptr_t DW_AT_artificial = 0x34; + static constexpr intptr_t DW_AT_decl_column = 0x39; + static constexpr intptr_t DW_AT_decl_file = 0x3a; + static constexpr intptr_t DW_AT_decl_line = 0x3b; + static constexpr intptr_t DW_AT_call_column = 0x57; + static constexpr intptr_t DW_AT_call_file = 0x58; + static constexpr intptr_t DW_AT_call_line = 0x59; - static const intptr_t DW_FORM_addr = 0x01; - static const intptr_t DW_FORM_string = 0x08; - static const intptr_t DW_FORM_flag = 0x0c; - static const intptr_t DW_FORM_udata = 0x0f; - static const intptr_t DW_FORM_ref4 = 0x13; - static const intptr_t DW_FORM_ref_udata = 0x15; - static const intptr_t DW_FORM_sec_offset = 0x17; + static constexpr intptr_t DW_FORM_addr = 0x01; + static constexpr intptr_t DW_FORM_string = 0x08; + static constexpr intptr_t DW_FORM_flag = 0x0c; + static constexpr intptr_t DW_FORM_udata = 0x0f; + static constexpr intptr_t DW_FORM_ref4 = 0x13; + static constexpr intptr_t DW_FORM_ref_udata = 0x15; + static constexpr intptr_t DW_FORM_sec_offset = 0x17; - static const intptr_t DW_INL_not_inlined = 0x0; - static const intptr_t DW_INL_inlined = 0x1; + static constexpr intptr_t DW_INL_not_inlined = 0x0; + static constexpr intptr_t DW_INL_inlined = 0x1; - static const intptr_t DW_LNS_copy = 0x1; - static const intptr_t DW_LNS_advance_pc = 0x2; - static const intptr_t DW_LNS_advance_line = 0x3; - static const intptr_t DW_LNS_set_file = 0x4; - static const intptr_t DW_LNS_set_column = 0x5; + static constexpr intptr_t DW_LNS_copy = 0x1; + static constexpr intptr_t DW_LNS_advance_pc = 0x2; + static constexpr intptr_t DW_LNS_advance_line = 0x3; + static constexpr intptr_t DW_LNS_set_file = 0x4; + static constexpr intptr_t DW_LNS_set_column = 0x5; - static const intptr_t DW_LNE_end_sequence = 0x01; - static const intptr_t DW_LNE_set_address = 0x02; + static constexpr intptr_t DW_LNE_end_sequence = 0x01; + static constexpr intptr_t DW_LNE_set_address = 0x02; public: // Public because they're also used in constructing .eh_frame ELF sections. - static const intptr_t DW_CFA_offset = 0x80; - static const intptr_t DW_CFA_val_offset = 0x14; - static const intptr_t DW_CFA_def_cfa = 0x0c; + static constexpr intptr_t DW_CFA_offset = 0x80; + static constexpr intptr_t DW_CFA_val_offset = 0x14; + static constexpr intptr_t DW_CFA_def_cfa = 0x0c; private: enum { diff --git a/runtime/vm/elf.cc b/runtime/vm/elf.cc index a0f1d257f5d..fe803b78ac3 100644 --- a/runtime/vm/elf.cc +++ b/runtime/vm/elf.cc @@ -431,7 +431,7 @@ class StringTable : public Section { return text_.buffer() + index; } - static const intptr_t kNotIndexed = CStringIntMapKeyValueTrait::kNoValue; + static constexpr intptr_t kNotIndexed = CStringIntMapKeyValueTrait::kNoValue; // Returns the index of |str| if it is present in the string table // and |kNotIndexed| otherwise. @@ -1000,7 +1000,7 @@ class BssSection : public ConcatenableBitsContainer { class PseudoSection : public Section { public: // All PseudoSections are aligned to target word size. - static const intptr_t kAlignment = compiler::target::kWordSize; + static constexpr intptr_t kAlignment = compiler::target::kWordSize; PseudoSection(bool allocate, bool executable, bool writable) : Section(elf::SectionHeaderType::SHT_NULL, @@ -1413,8 +1413,8 @@ void Elf::FinalizeEhFrame() { // DW_CFA_val_offset. const intptr_t kDataAlignment = -compiler::target::kWordSize; - static const uint8_t DW_EH_PE_pcrel = 0x10; - static const uint8_t DW_EH_PE_sdata4 = 0x0b; + static constexpr uint8_t DW_EH_PE_pcrel = 0x10; + static constexpr uint8_t DW_EH_PE_sdata4 = 0x0b; ZoneWriteStream stream(zone(), kInitialDwarfBufferSize); DwarfElfStream dwarf_stream(zone_, &stream); diff --git a/runtime/vm/exceptions.cc b/runtime/vm/exceptions.cc index 0294c306ecb..b5d317345d0 100644 --- a/runtime/vm/exceptions.cc +++ b/runtime/vm/exceptions.cc @@ -56,7 +56,7 @@ class PreallocatedStackTraceBuilder : public StackTraceBuilder { void AddFrame(const Object& code, uword pc_offset) override; private: - static const int kNumTopframes = StackTrace::kPreallocatedStackdepth / 2; + static constexpr int kNumTopframes = StackTrace::kPreallocatedStackdepth / 2; const StackTrace& stacktrace_; intptr_t cur_index_; diff --git a/runtime/vm/field_table.h b/runtime/vm/field_table.h index fbdd56831ac..97cd723eb8d 100644 --- a/runtime/vm/field_table.h +++ b/runtime/vm/field_table.h @@ -91,8 +91,8 @@ class FieldTable { void VisitObjectPointers(ObjectPointerVisitor* visitor); - static const int kInitialCapacity = 512; - static const int kCapacityIncrement = 256; + static constexpr int kInitialCapacity = 512; + static constexpr int kCapacityIncrement = 256; private: friend class GCMarker; diff --git a/runtime/vm/globals.h b/runtime/vm/globals.h index bcee6518127..3af311ebfdf 100644 --- a/runtime/vm/globals.h +++ b/runtime/vm/globals.h @@ -173,9 +173,9 @@ typedef uword cpp_vtable; // Zap value used to indicate uninitialized handle area (debug purposes). #if defined(ARCH_IS_32_BIT) -static const uword kZapUninitializedWord = 0xabababab; +static constexpr uword kZapUninitializedWord = 0xabababab; #else -static const uword kZapUninitializedWord = 0xabababababababab; +static constexpr uword kZapUninitializedWord = 0xabababababababab; #endif // Macros to get the contents of the fp register. diff --git a/runtime/vm/handles.h b/runtime/vm/handles.h index a8a5b57b8e8..7a849a7f4ee 100644 --- a/runtime/vm/handles.h +++ b/runtime/vm/handles.h @@ -232,18 +232,18 @@ class Handles { }; #if defined(DEBUG) -static const int kVMHandleSizeInWords = 3; -static const int kOffsetOfIsZoneHandle = 2; +static constexpr int kVMHandleSizeInWords = 3; +static constexpr int kOffsetOfIsZoneHandle = 2; #else -static const int kVMHandleSizeInWords = 2; +static constexpr int kVMHandleSizeInWords = 2; #endif -static const int kVMHandlesPerChunk = 63; -static const int kOffsetOfRawPtr = kWordSize; +static constexpr int kVMHandlesPerChunk = 63; +static constexpr int kOffsetOfRawPtr = kWordSize; class VMHandles : public Handles { public: - static const int kOffsetOfRawPtrInHandle = kOffsetOfRawPtr; + static constexpr int kOffsetOfRawPtrInHandle = kOffsetOfRawPtr; VMHandles() : Handles() { diff --git a/runtime/vm/handles_test.cc b/runtime/vm/handles_test.cc index aef41d9a29a..d838186cfbe 100644 --- a/runtime/vm/handles_test.cc +++ b/runtime/vm/handles_test.cc @@ -20,7 +20,7 @@ ISOLATE_UNIT_TEST_CASE(AllocateZoneHandle) { #endif // The previously run stub code generation may have created zone handles. int initial_count = VMHandles::ZoneHandleCount(); - static const int kNumHandles = 65; + const int kNumHandles = 65; // Create some zone handles. for (int i = 0; i < kNumHandles; i++) { const Smi& handle = Smi::ZoneHandle(Smi::New(i)); @@ -43,7 +43,7 @@ ISOLATE_UNIT_TEST_CASE(AllocateScopeHandle) { FLAG_trace_handles = true; #endif int32_t handle_count = VMHandles::ScopedHandleCount(); - static const int kNumHandles = 65; + const int kNumHandles = 65; // Create some scoped handles. { Thread* thread = Thread::Current(); diff --git a/runtime/vm/hash_table.h b/runtime/vm/hash_table.h index 4d84c7fb484..4e5c1ca64c4 100644 --- a/runtime/vm/hash_table.h +++ b/runtime/vm/hash_table.h @@ -15,7 +15,7 @@ namespace dart { struct ArrayStorageTraits { using ArrayHandle = Array; using ArrayPtr = dart::ArrayPtr; - static const intptr_t ArrayCid = kArrayCid; + static constexpr intptr_t ArrayCid = kArrayCid; static ArrayHandle& PtrToHandle(ArrayPtr ptr) { return Array::Handle(ptr); } @@ -47,7 +47,7 @@ struct ArrayStorageTraits { struct WeakArrayStorageTraits { using ArrayHandle = WeakArray; using ArrayPtr = dart::WeakArrayPtr; - static const intptr_t ArrayCid = kWeakArrayCid; + static constexpr intptr_t ArrayCid = kWeakArrayCid; static ArrayHandle& PtrToHandle(ArrayPtr ptr) { return WeakArray::Handle(ptr); @@ -458,21 +458,21 @@ class HashTable : public HashTableBase { } protected: - static const intptr_t kOccupiedEntriesIndex = 0; - static const intptr_t kDeletedEntriesIndex = 1; + static constexpr intptr_t kOccupiedEntriesIndex = 0; + static constexpr intptr_t kDeletedEntriesIndex = 1; #if defined(PRODUCT) - static const intptr_t kHeaderSize = kDeletedEntriesIndex + 1; + static constexpr intptr_t kHeaderSize = kDeletedEntriesIndex + 1; #else - static const intptr_t kNumGrowsIndex = 2; - static const intptr_t kNumLT5LookupsIndex = 3; - static const intptr_t kNumLT25LookupsIndex = 4; - static const intptr_t kNumGT25LookupsIndex = 5; - static const intptr_t kNumProbesIndex = 6; - static const intptr_t kHeaderSize = kNumProbesIndex + 1; + static constexpr intptr_t kNumGrowsIndex = 2; + static constexpr intptr_t kNumLT5LookupsIndex = 3; + static constexpr intptr_t kNumLT25LookupsIndex = 4; + static constexpr intptr_t kNumGT25LookupsIndex = 5; + static constexpr intptr_t kNumProbesIndex = 6; + static constexpr intptr_t kHeaderSize = kNumProbesIndex + 1; #endif - static const intptr_t kMetaDataIndex = kHeaderSize; - static const intptr_t kFirstKeyIndex = kHeaderSize + kMetaDataSize; - static const intptr_t kEntrySize = 1 + kPayloadSize; + static constexpr intptr_t kMetaDataIndex = kHeaderSize; + static constexpr intptr_t kFirstKeyIndex = kHeaderSize + kMetaDataSize; + static constexpr intptr_t kEntrySize = 1 + kPayloadSize; intptr_t KeyIndex(intptr_t entry) const { ASSERT(0 <= entry && entry < NumEntries()); @@ -537,7 +537,7 @@ class UnorderedHashTable typedef HashTable BaseTable; typedef typename StorageTraits::ArrayPtr ArrayPtr; typedef typename StorageTraits::ArrayHandle ArrayHandle; - static const intptr_t kPayloadSize = kUserPayloadSize; + static constexpr intptr_t kPayloadSize = kUserPayloadSize; explicit UnorderedHashTable(ArrayPtr data) : BaseTable(Thread::Current()->zone(), data) {} UnorderedHashTable(Zone* zone, ArrayPtr data) : BaseTable(zone, data) {} diff --git a/runtime/vm/instructions_arm.h b/runtime/vm/instructions_arm.h index eb3c3901ef5..e751331caa0 100644 --- a/runtime/vm/instructions_arm.h +++ b/runtime/vm/instructions_arm.h @@ -170,7 +170,7 @@ class ReturnPattern : public ValueObject { explicit ReturnPattern(uword pc); // bx_lr = 1. - static const int kLengthInBytes = 1 * Instr::kInstrSize; + static constexpr int kLengthInBytes = 1 * Instr::kInstrSize; int pattern_length_in_bytes() const { return kLengthInBytes; } @@ -190,7 +190,7 @@ class PcRelativeCallPatternBase : public ValueObject { explicit PcRelativeCallPatternBase(uword pc) : pc_(pc) {} - static const int kLengthInBytes = 1 * Instr::kInstrSize; + static constexpr int kLengthInBytes = 1 * Instr::kInstrSize; int32_t distance() { #if !defined(DART_PRECOMPILED_RUNTIME) @@ -251,7 +251,7 @@ class PcRelativeTrampolineJumpPattern : public ValueObject { USE(pattern_start_); } - static const int kLengthInBytes = 3 * Instr::kInstrSize; + static constexpr int kLengthInBytes = 3 * Instr::kInstrSize; void Initialize(); @@ -263,10 +263,10 @@ class PcRelativeTrampolineJumpPattern : public ValueObject { // This offset must be applied to account for the fact that // a) the actual "branch" is only in the 3rd instruction // b) when reading the PC it reports current instruction + 8 - static const intptr_t kDistanceOffset = -4 * Instr::kInstrSize; + static constexpr intptr_t kDistanceOffset = -4 * Instr::kInstrSize; // add PC, PC, TMP lsl #0 - static const uint32_t kAddPcEncoding = + static constexpr uint32_t kAddPcEncoding = (ADD << kOpcodeShift) | (AL << kConditionShift) | (PC << kRnShift) | (PC << kRdShift) | (TMP << kRmShift); diff --git a/runtime/vm/instructions_arm64.h b/runtime/vm/instructions_arm64.h index 482d0c97e93..ac715a4f96d 100644 --- a/runtime/vm/instructions_arm64.h +++ b/runtime/vm/instructions_arm64.h @@ -180,7 +180,7 @@ class ReturnPattern : public ValueObject { explicit ReturnPattern(uword pc); // bx_lr = 1. - static const int kLengthInBytes = 1 * Instr::kInstrSize; + static constexpr int kLengthInBytes = 1 * Instr::kInstrSize; int pattern_length_in_bytes() const { return kLengthInBytes; } @@ -198,7 +198,7 @@ class PcRelativePatternBase : public ValueObject { explicit PcRelativePatternBase(uword pc) : pc_(pc) {} - static const int kLengthInBytes = 1 * Instr::kInstrSize; + static constexpr int kLengthInBytes = 1 * Instr::kInstrSize; int32_t distance() { #if !defined(DART_PRECOMPILED_RUNTIME) @@ -261,7 +261,7 @@ class PcRelativeTrampolineJumpPattern : public ValueObject { USE(pattern_start_); } - static const int kLengthInBytes = 4 * Instr::kInstrSize; + static constexpr int kLengthInBytes = 4 * Instr::kInstrSize; void Initialize(); @@ -273,19 +273,19 @@ class PcRelativeTrampolineJumpPattern : public ValueObject { // This offset must be applied to account for the fact that // a) the actual "branch" is only in the 3rd instruction // b) when reading the PC it reports current instruction + 8 - static const intptr_t kDistanceOffset = -5 * Instr::kInstrSize; + static constexpr intptr_t kDistanceOffset = -5 * Instr::kInstrSize; // adr TMP, #lower16 (same as TMP = PC + #lower16) - static const uint32_t kAdrEncoding = (1 << 28) | (TMP << kRdShift); + static constexpr uint32_t kAdrEncoding = (1 << 28) | (TMP << kRdShift); // movz TMP2, #higher16 lsl 16 - static const uint32_t kMovzEncoding = MOVZ | (1 << kHWShift) | TMP2; + static constexpr uint32_t kMovzEncoding = MOVZ | (1 << kHWShift) | TMP2; // add TMP, TMP, TMP2, SXTW - static const uint32_t kAddTmpTmp2 = 0x8b31c210; + static constexpr uint32_t kAddTmpTmp2 = 0x8b31c210; // br TMP - static const uint32_t kJumpEncoding = BR | (TMP << kRnShift); + static constexpr uint32_t kJumpEncoding = BR | (TMP << kRnShift); uword pattern_start_; }; diff --git a/runtime/vm/instructions_ia32.h b/runtime/vm/instructions_ia32.h index ff1db5e5f76..2f399b22666 100644 --- a/runtime/vm/instructions_ia32.h +++ b/runtime/vm/instructions_ia32.h @@ -77,7 +77,7 @@ class CallPattern : public InstructionPattern { } private: - static const int kLengthInBytes = 5; + static constexpr int kLengthInBytes = 5; DISALLOW_COPY_AND_ASSIGN(CallPattern); }; @@ -92,7 +92,7 @@ class ReturnPattern : public InstructionPattern { static int pattern_length_in_bytes() { return kLengthInBytes; } private: - static const int kLengthInBytes = 1; + static constexpr int kLengthInBytes = 1; }; // push ebp @@ -109,7 +109,7 @@ class ProloguePattern : public InstructionPattern { static int pattern_length_in_bytes() { return kLengthInBytes; } private: - static const int kLengthInBytes = 3; + static constexpr int kLengthInBytes = 3; }; // mov ebp, esp @@ -126,7 +126,7 @@ class SetFramePointerPattern static int pattern_length_in_bytes() { return kLengthInBytes; } private: - static const int kLengthInBytes = 2; + static constexpr int kLengthInBytes = 2; }; } // namespace dart diff --git a/runtime/vm/instructions_riscv.h b/runtime/vm/instructions_riscv.h index 6314964533c..e2c5072b443 100644 --- a/runtime/vm/instructions_riscv.h +++ b/runtime/vm/instructions_riscv.h @@ -167,7 +167,7 @@ class ReturnPattern : public ValueObject { explicit ReturnPattern(uword pc); // ret = 1 compressed instruction - static const intptr_t kLengthInBytes = 2; + static constexpr intptr_t kLengthInBytes = 2; int pattern_length_in_bytes() const { return kLengthInBytes; } diff --git a/runtime/vm/instructions_x64.h b/runtime/vm/instructions_x64.h index 171daed283c..0fcc52bb005 100644 --- a/runtime/vm/instructions_x64.h +++ b/runtime/vm/instructions_x64.h @@ -71,7 +71,7 @@ class ReturnPattern : public InstructionPattern { static int pattern_length_in_bytes() { return kLengthInBytes; } private: - static const int kLengthInBytes = 1; + static constexpr int kLengthInBytes = 1; }; // push rbp @@ -89,7 +89,7 @@ class ProloguePattern : public InstructionPattern { static int pattern_length_in_bytes() { return kLengthInBytes; } private: - static const int kLengthInBytes = 4; + static constexpr int kLengthInBytes = 4; }; // mov rbp, rsp @@ -106,13 +106,13 @@ class SetFramePointerPattern static int pattern_length_in_bytes() { return kLengthInBytes; } private: - static const int kLengthInBytes = 3; + static constexpr int kLengthInBytes = 3; }; // callq *[rip+offset] class PcRelativeCallPattern : public InstructionPattern { public: - static const int kLengthInBytes = 5; + static constexpr int kLengthInBytes = 5; // Theoretically we can encode offsets 5 bytes more than INT_MAX since the // instruction encoding uses the PC after current instruction. @@ -162,7 +162,7 @@ class PcRelativeCallPattern : public InstructionPattern { // allow testing of trampolines on X64 we have it nonetheless) class PcRelativeTrampolineJumpPattern : public ValueObject { public: - static const int kLengthInBytes = 5; + static constexpr int kLengthInBytes = 5; explicit PcRelativeTrampolineJumpPattern(uword pattern_start) : pattern_start_(pattern_start) {} diff --git a/runtime/vm/isolate.cc b/runtime/vm/isolate.cc index dfd616de4c7..6567f2f3e8e 100644 --- a/runtime/vm/isolate.cc +++ b/runtime/vm/isolate.cc @@ -2166,7 +2166,7 @@ bool Isolate::VerifyTerminateCapability(const Object& capability) const { bool Isolate::AddResumeCapability(const Capability& capability) { // Ensure a limit for the number of resume capabilities remembered. - static const intptr_t kMaxResumeCapabilities = + const intptr_t kMaxResumeCapabilities = compiler::target::kSmiMax / (6 * kWordSize); const GrowableObjectArray& caps = GrowableObjectArray::Handle( @@ -2218,8 +2218,7 @@ bool Isolate::RemoveResumeCapability(const Capability& capability) { void Isolate::AddExitListener(const SendPort& listener, const Instance& response) { // Ensure a limit for the number of listeners remembered. - static const intptr_t kMaxListeners = - compiler::target::kSmiMax / (12 * kWordSize); + const intptr_t kMaxListeners = compiler::target::kSmiMax / (12 * kWordSize); const GrowableObjectArray& listeners = GrowableObjectArray::Handle( current_zone(), isolate_object_store()->exit_listeners()); @@ -2286,8 +2285,7 @@ void Isolate::NotifyExitListeners() { void Isolate::AddErrorListener(const SendPort& listener) { // Ensure a limit for the number of listeners remembered. - static const intptr_t kMaxListeners = - compiler::target::kSmiMax / (6 * kWordSize); + const intptr_t kMaxListeners = compiler::target::kSmiMax / (6 * kWordSize); const GrowableObjectArray& listeners = GrowableObjectArray::Handle( current_zone(), isolate_object_store()->error_listeners()); diff --git a/runtime/vm/isolate_test.cc b/runtime/vm/isolate_test.cc index e620dadc70f..8e8b85d1799 100644 --- a/runtime/vm/isolate_test.cc +++ b/runtime/vm/isolate_test.cc @@ -106,8 +106,8 @@ TEST_CASE(IsolateSpawn_PackageUri) { class InterruptChecker : public ThreadPool::Task { public: - static const intptr_t kTaskCount; - static const intptr_t kIterations; + static constexpr intptr_t kTaskCount = 5; + static constexpr intptr_t kIterations = 10; InterruptChecker(Thread* thread, ThreadBarrier* barrier) : thread_(thread), barrier_(barrier) {} @@ -139,9 +139,6 @@ class InterruptChecker : public ThreadPool::Task { ThreadBarrier* barrier_; }; -const intptr_t InterruptChecker::kTaskCount = 5; -const intptr_t InterruptChecker::kIterations = 10; - // Test and document usage of Isolate::HasInterruptsScheduled. // // Go through a number of rounds of scheduling interrupts and waiting until all diff --git a/runtime/vm/json_writer.cc b/runtime/vm/json_writer.cc index 39447c61b52..6fe6c93ccf7 100644 --- a/runtime/vm/json_writer.cc +++ b/runtime/vm/json_writer.cc @@ -27,7 +27,7 @@ class MaybeOnStackBuffer { char* p() { return p_; } private: - static const intptr_t kOnStackBufferCapacity = 4096; + static constexpr intptr_t kOnStackBufferCapacity = 4096; char* p_; char buffer_[kOnStackBufferCapacity]; }; diff --git a/runtime/vm/kernel.h b/runtime/vm/kernel.h index cd2c9daadaa..51c4d5e2dda 100644 --- a/runtime/vm/kernel.h +++ b/runtime/vm/kernel.h @@ -18,7 +18,7 @@ namespace dart { namespace kernel { class NameIndex { public: - static const int kInvalidName = -1; + static constexpr int kInvalidName = -1; NameIndex() : value_(kInvalidName) {} explicit NameIndex(int value) : value_(value) {} diff --git a/runtime/vm/kernel_binary.h b/runtime/vm/kernel_binary.h index b774d81eb1a..7d3ffbb8aa9 100644 --- a/runtime/vm/kernel_binary.h +++ b/runtime/vm/kernel_binary.h @@ -175,9 +175,9 @@ static const uint32_t kSupportedKernelFormatVersion = 101; V(SpecializedVariableSet, 232) \ V(SpecializedIntLiteral, 240) -static const intptr_t kSpecializedTagHighBits = 0xe0; -static const intptr_t kSpecializedTagMask = 0xf8; -static const intptr_t kSpecializedPayloadMask = 0x7; +static constexpr intptr_t kSpecializedTagHighBits = 0xe0; +static constexpr intptr_t kSpecializedTagMask = 0xf8; +static constexpr intptr_t kSpecializedPayloadMask = 0x7; enum Tag { #define DECLARE(Name, value) k##Name = value, @@ -264,12 +264,12 @@ enum class FunctionAccessKind { kNullable, }; -static const int SpecializedIntLiteralBias = 3; -static const int LibraryCountFieldCountFromEnd = 1; -static const int KernelFormatVersionOffset = 4; -static const int SourceTableFieldCountFromFirstLibraryOffset = 9; +static constexpr int SpecializedIntLiteralBias = 3; +static constexpr int LibraryCountFieldCountFromEnd = 1; +static constexpr int KernelFormatVersionOffset = 4; +static constexpr int SourceTableFieldCountFromFirstLibraryOffset = 9; -static const int HeaderSize = 8; // 'magic', 'formatVersion'. +static constexpr int HeaderSize = 8; // 'magic', 'formatVersion'. class Reader : public ValueObject { public: diff --git a/runtime/vm/kernel_isolate.cc b/runtime/vm/kernel_isolate.cc index da81f00cb0e..bc843296ead 100644 --- a/runtime/vm/kernel_isolate.cc +++ b/runtime/vm/kernel_isolate.cc @@ -42,26 +42,6 @@ DEFINE_FLAG(charp, "URI scheme that replaces filepaths prefixes specified" " by kernel_multiroot_filepaths option"); -// Tags used to indicate different requests to the dart frontend. -// -// Current tags include the following: -// 0 - Perform normal compilation. -// 1 - Update in-memory file system with in-memory sources (used by tests). -// 2 - Accept last compilation result. -// 3 - APP JIT snapshot training run for kernel_service. -// 4 - Compile expressions in context (used by expression evaluation). -// 5 - Generate dependencies used to create a dependencies file. -// 6 - Triggers shutdown of the kernel isolate. -// 7 - Reject last compilation result. -const int KernelIsolate::kCompileTag = 0; -const int KernelIsolate::kUpdateSourcesTag = 1; -const int KernelIsolate::kAcceptTag = 2; -const int KernelIsolate::kTrainTag = 3; -const int KernelIsolate::kCompileExpressionTag = 4; -const int KernelIsolate::kListDependenciesTag = 5; -const int KernelIsolate::kNotifyIsolateShutdown = 6; -const int KernelIsolate::kRejectTag = 7; - const char* KernelIsolate::kName = DART_KERNEL_ISOLATE_NAME; Dart_IsolateGroupCreateCallback KernelIsolate::create_group_callback_ = nullptr; Monitor* KernelIsolate::monitor_ = new Monitor(); diff --git a/runtime/vm/kernel_isolate.h b/runtime/vm/kernel_isolate.h index c77984e6fff..05bfda4c622 100644 --- a/runtime/vm/kernel_isolate.h +++ b/runtime/vm/kernel_isolate.h @@ -24,14 +24,26 @@ class KernelIsolate : public AllStatic { public: static const char* kName; - static const int kCompileTag; - static const int kUpdateSourcesTag; - static const int kAcceptTag; - static const int kTrainTag; - static const int kCompileExpressionTag; - static const int kListDependenciesTag; - static const int kNotifyIsolateShutdown; - static const int kRejectTag; + + // Tags used to indicate different requests to the dart frontend. + // + // Current tags include the following: + // 0 - Perform normal compilation. + // 1 - Update in-memory file system with in-memory sources (used by tests). + // 2 - Accept last compilation result. + // 3 - APP JIT snapshot training run for kernel_service. + // 4 - Compile expressions in context (used by expression evaluation). + // 5 - Generate dependencies used to create a dependencies file. + // 6 - Triggers shutdown of the kernel isolate. + // 7 - Reject last compilation result. + static constexpr int kCompileTag = 0; + static constexpr int kUpdateSourcesTag = 1; + static constexpr int kAcceptTag = 2; + static constexpr int kTrainTag = 3; + static constexpr int kCompileExpressionTag = 4; + static constexpr int kListDependenciesTag = 5; + static constexpr int kNotifyIsolateShutdown = 6; + static constexpr int kRejectTag = 7; static void InitializeState(); static bool Start(); diff --git a/runtime/vm/memory_region_test.cc b/runtime/vm/memory_region_test.cc index 0dd877acd55..35f65541e0c 100644 --- a/runtime/vm/memory_region_test.cc +++ b/runtime/vm/memory_region_test.cc @@ -18,14 +18,14 @@ static void DeleteRegion(const MemoryRegion& region) { } VM_UNIT_TEST_CASE(NullRegion) { - static const uword kSize = 512; + const uword kSize = 512; MemoryRegion region(nullptr, kSize); EXPECT(region.pointer() == nullptr); EXPECT_EQ(kSize, region.size()); } VM_UNIT_TEST_CASE(NewRegion) { - static const uword kSize = 1024; + const uword kSize = 1024; MemoryRegion region(NewRegion(kSize), kSize); EXPECT_EQ(kSize, region.size()); EXPECT(region.pointer() != nullptr); @@ -37,9 +37,9 @@ VM_UNIT_TEST_CASE(NewRegion) { } VM_UNIT_TEST_CASE(Subregion) { - static const uword kSize = 1024; - static const uword kSubOffset = 128; - static const uword kSubSize = 512; + const uword kSize = 1024; + const uword kSubOffset = 128; + const uword kSubSize = 512; MemoryRegion region(NewRegion(kSize), kSize); MemoryRegion sub_region; sub_region.Subregion(region, kSubOffset, kSubSize); @@ -56,9 +56,9 @@ VM_UNIT_TEST_CASE(Subregion) { } VM_UNIT_TEST_CASE(ExtendedRegion) { - static const uword kSize = 1024; - static const uword kSubSize = 512; - static const uword kExtendSize = 512; + const uword kSize = 1024; + const uword kSubSize = 512; + const uword kExtendSize = 512; MemoryRegion region(NewRegion(kSize), kSize); MemoryRegion sub_region; sub_region.Subregion(region, 0, kSubSize); diff --git a/runtime/vm/message_snapshot.cc b/runtime/vm/message_snapshot.cc index ceccaf9db82..597c7796576 100644 --- a/runtime/vm/message_snapshot.cc +++ b/runtime/vm/message_snapshot.cc @@ -2753,8 +2753,8 @@ class TwoByteStringMessageDeserializationCluster } }; -static const intptr_t kFirstReference = 1; -static const intptr_t kUnallocatedReference = -1; +static constexpr intptr_t kFirstReference = 1; +static constexpr intptr_t kUnallocatedReference = -1; BaseSerializer::BaseSerializer(Thread* thread, Zone* zone) : StackResource(thread), diff --git a/runtime/vm/native_entry.h b/runtime/vm/native_entry.h index 5022ffcf08d..67b65ee4d09 100644 --- a/runtime/vm/native_entry.h +++ b/runtime/vm/native_entry.h @@ -95,8 +95,8 @@ void DartNativeThrowArgumentException(const Instance& instance); // Helper class for resolving and handling native functions. class NativeEntry : public AllStatic { public: - static const intptr_t kNumArguments = 1; - static const intptr_t kNumCallWrapperArguments = 2; + static constexpr intptr_t kNumArguments = 1; + static constexpr intptr_t kNumCallWrapperArguments = 2; // Resolve specified dart native function to the actual native entrypoint. static NativeFunction ResolveNative(const Library& library, diff --git a/runtime/vm/native_symbol_win.cc b/runtime/vm/native_symbol_win.cc index 34ce7a836aa..84b9409ce35 100644 --- a/runtime/vm/native_symbol_win.cc +++ b/runtime/vm/native_symbol_win.cc @@ -60,8 +60,8 @@ char* NativeSymbolResolver::LookupSymbolName(uword pc, uword* start) { #ifdef DART_TARGET_OS_WINDOWS_UWP return nullptr; #else - static const intptr_t kMaxNameLength = 2048; - static const intptr_t kSymbolInfoSize = sizeof(SYMBOL_INFO); // NOLINT. + const intptr_t kMaxNameLength = 2048; + const intptr_t kSymbolInfoSize = sizeof(SYMBOL_INFO); // NOLINT. static char buffer[kSymbolInfoSize + kMaxNameLength]; static char name_buffer[kMaxNameLength]; MutexLocker lock(lock_); diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc index 10464a7521f..c7ac721cfbb 100644 --- a/runtime/vm/object.cc +++ b/runtime/vm/object.cc @@ -189,8 +189,6 @@ ClassPtr Object::weak_serialization_reference_class_ = static_cast(RAW_NULL); ClassPtr Object::weak_array_class_ = static_cast(RAW_NULL); -const double MegamorphicCache::kLoadFactor = 0.50; - static void AppendSubString(BaseTextBuffer* buffer, const char* name, intptr_t start_pos, @@ -2933,7 +2931,7 @@ ObjectPtr Object::Clone(const Object& orig, // Copy the body of the original into the clone. uword orig_addr = UntaggedObject::ToAddr(orig.ptr()); uword clone_addr = UntaggedObject::ToAddr(raw_clone); - static const intptr_t kHeaderSizeInBytes = sizeof(UntaggedObject); + const intptr_t kHeaderSizeInBytes = sizeof(UntaggedObject); if (load_with_relaxed_atomics) { auto orig_atomics_ptr = reinterpret_cast*>(orig_addr); auto clone_ptr = reinterpret_cast(clone_addr); @@ -14300,7 +14298,7 @@ ObjectPtr Library::EvaluateCompiledExpression( void Library::InitNativeWrappersLibrary(IsolateGroup* isolate_group, bool is_kernel) { - static const int kNumNativeWrappersClasses = 4; + const int kNumNativeWrappersClasses = 4; COMPILE_ASSERT((kNumNativeWrappersClasses > 0) && (kNumNativeWrappersClasses < 10)); Thread* thread = Thread::Current(); @@ -14314,8 +14312,8 @@ void Library::InitNativeWrappersLibrary(IsolateGroup* isolate_group, native_flds_lib.Register(thread); native_flds_lib.SetLoadInProgress(); isolate_group->object_store()->set_native_wrappers_library(native_flds_lib); - static const char* const kNativeWrappersClass = "NativeFieldWrapperClass"; - static const int kNameLength = 25; + const char* const kNativeWrappersClass = "NativeFieldWrapperClass"; + const int kNameLength = 25; ASSERT(kNameLength == (strlen(kNativeWrappersClass) + 1 + 1)); char name_buffer[kNameLength]; String& cls_name = String::Handle(zone); @@ -25645,8 +25643,8 @@ MapPtr Map::NewDefault(intptr_t class_id, Heap::Space space) { const TypedData& index = TypedData::Handle( TypedData::New(kTypedDataUint32ArrayCid, kInitialIndexSize, space)); // On 32-bit, the top bits are wasted to avoid Mint allocation. - static const intptr_t kAvailableBits = (kSmiBits >= 32) ? 32 : kSmiBits; - static const intptr_t kInitialHashMask = + const intptr_t kAvailableBits = (kSmiBits >= 32) ? 32 : kSmiBits; + const intptr_t kInitialHashMask = (1 << (kAvailableBits - kInitialIndexBits)) - 1; return Map::New(class_id, data, index, kInitialHashMask, 0, 0, space); } @@ -25829,8 +25827,8 @@ SetPtr Set::NewDefault(intptr_t class_id, Heap::Space space) { const TypedData& index = TypedData::Handle( TypedData::New(kTypedDataUint32ArrayCid, kInitialIndexSize, space)); // On 32-bit, the top bits are wasted to avoid Mint allocation. - static const intptr_t kAvailableBits = (kSmiBits >= 32) ? 32 : kSmiBits; - static const intptr_t kInitialHashMask = + const intptr_t kAvailableBits = (kSmiBits >= 32) ? 32 : kSmiBits; + const intptr_t kInitialHashMask = (1 << (kAvailableBits - kInitialIndexBits)) - 1; return Set::New(class_id, data, index, kInitialHashMask, 0, 0, space); } diff --git a/runtime/vm/object.h b/runtime/vm/object.h index 364c2dd1ed6..d4e488ee42f 100644 --- a/runtime/vm/object.h +++ b/runtime/vm/object.h @@ -311,7 +311,7 @@ class Object { // We use 30 bits for the hash code so hashes in a snapshot taken on a // 64-bit architecture stay in Smi range when loaded on a 32-bit // architecture. - static const intptr_t kHashBits = 30; + static constexpr intptr_t kHashBits = 30; static ObjectPtr RawCast(ObjectPtr obj) { return obj; } @@ -1253,7 +1253,7 @@ class Class : public Object { TypeArgumentsPtr InstantiateToBounds(Thread* thread) const; // If this class is parameterized, each instance has a type_arguments field. - static const intptr_t kNoTypeArguments = -1; + static constexpr intptr_t kNoTypeArguments = -1; intptr_t host_type_arguments_field_offset() const { ASSERT(is_type_finalized() || is_prefinalized()); if (untag()->host_type_arguments_field_offset_in_words_ == @@ -1986,10 +1986,10 @@ class Class : public Object { UnboxedFieldBitmap CalculateFieldOffsets() const; // functions_hash_table is in use iff there are at least this many functions. - static const intptr_t kFunctionLookupHashThreshold = 16; + static constexpr intptr_t kFunctionLookupHashThreshold = 16; // Initial value for the cached number of type arguments. - static const intptr_t kUnknownNumTypeArguments = -1; + static constexpr intptr_t kUnknownNumTypeArguments = -1; int16_t num_type_arguments() const { return LoadNonPointer( @@ -2326,7 +2326,7 @@ class ICData : public CallSiteData { #undef DEFINE_ENUM_LIST }; - static const intptr_t kLastRecordedDeoptReason = kDeoptUnknown - 1; + static constexpr intptr_t kLastRecordedDeoptReason = kDeoptUnknown - 1; enum DeoptFlags { // Deoptimization is caused by an optimistically hoisted instruction. @@ -3350,7 +3350,7 @@ class Function : public Object { void InheritKernelOffsetFrom(const Function& src) const; void InheritKernelOffsetFrom(const Field& src) const; - static const intptr_t kMaxInstructionCount = (1 << 16) - 1; + static constexpr intptr_t kMaxInstructionCount = (1 << 16) - 1; void SetOptimizedInstructionCountClamped(uintptr_t value) const { if (value > kMaxInstructionCount) value = kMaxInstructionCount; @@ -5154,8 +5154,8 @@ class Library : public Object { void EnsureTopLevelClassIsFinalized() const; private: - static const int kInitialImportsCapacity = 4; - static const int kImportsCapacityIncrement = 8; + static constexpr int kInitialImportsCapacity = 4; + static constexpr int kImportsCapacityIncrement = 8; static LibraryPtr New(); @@ -5405,9 +5405,9 @@ class ObjectPool : public Object { return 0; } - static const intptr_t kBytesPerElement = + static constexpr intptr_t kBytesPerElement = sizeof(UntaggedObjectPool::Entry) + sizeof(uint8_t); - static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; + static constexpr intptr_t kMaxElements = kSmiMax / kBytesPerElement; static intptr_t InstanceSize(intptr_t len) { // Ensure that variable length data is not adding to the object length. @@ -5491,35 +5491,35 @@ class Instructions : public Object { // Note: We keep the checked entrypoint offsets even (emitting NOPs if // necessary) to allow them to be seen as Smis by the GC. #if defined(TARGET_ARCH_IA32) - static const intptr_t kMonomorphicEntryOffsetJIT = 6; - static const intptr_t kPolymorphicEntryOffsetJIT = 36; - static const intptr_t kMonomorphicEntryOffsetAOT = 0; - static const intptr_t kPolymorphicEntryOffsetAOT = 0; + static constexpr intptr_t kMonomorphicEntryOffsetJIT = 6; + static constexpr intptr_t kPolymorphicEntryOffsetJIT = 36; + static constexpr intptr_t kMonomorphicEntryOffsetAOT = 0; + static constexpr intptr_t kPolymorphicEntryOffsetAOT = 0; #elif defined(TARGET_ARCH_X64) - static const intptr_t kMonomorphicEntryOffsetJIT = 8; - static const intptr_t kPolymorphicEntryOffsetJIT = 42; - static const intptr_t kMonomorphicEntryOffsetAOT = 8; - static const intptr_t kPolymorphicEntryOffsetAOT = 22; + static constexpr intptr_t kMonomorphicEntryOffsetJIT = 8; + static constexpr intptr_t kPolymorphicEntryOffsetJIT = 42; + static constexpr intptr_t kMonomorphicEntryOffsetAOT = 8; + static constexpr intptr_t kPolymorphicEntryOffsetAOT = 22; #elif defined(TARGET_ARCH_ARM) - static const intptr_t kMonomorphicEntryOffsetJIT = 0; - static const intptr_t kPolymorphicEntryOffsetJIT = 44; - static const intptr_t kMonomorphicEntryOffsetAOT = 0; - static const intptr_t kPolymorphicEntryOffsetAOT = 16; + static constexpr intptr_t kMonomorphicEntryOffsetJIT = 0; + static constexpr intptr_t kPolymorphicEntryOffsetJIT = 44; + static constexpr intptr_t kMonomorphicEntryOffsetAOT = 0; + static constexpr intptr_t kPolymorphicEntryOffsetAOT = 16; #elif defined(TARGET_ARCH_ARM64) - static const intptr_t kMonomorphicEntryOffsetJIT = 8; - static const intptr_t kPolymorphicEntryOffsetJIT = 52; - static const intptr_t kMonomorphicEntryOffsetAOT = 8; - static const intptr_t kPolymorphicEntryOffsetAOT = 24; + static constexpr intptr_t kMonomorphicEntryOffsetJIT = 8; + static constexpr intptr_t kPolymorphicEntryOffsetJIT = 52; + static constexpr intptr_t kMonomorphicEntryOffsetAOT = 8; + static constexpr intptr_t kPolymorphicEntryOffsetAOT = 24; #elif defined(TARGET_ARCH_RISCV32) - static const intptr_t kMonomorphicEntryOffsetJIT = 6; - static const intptr_t kPolymorphicEntryOffsetJIT = 44; - static const intptr_t kMonomorphicEntryOffsetAOT = 6; - static const intptr_t kPolymorphicEntryOffsetAOT = 18; + static constexpr intptr_t kMonomorphicEntryOffsetJIT = 6; + static constexpr intptr_t kPolymorphicEntryOffsetJIT = 44; + static constexpr intptr_t kMonomorphicEntryOffsetAOT = 6; + static constexpr intptr_t kPolymorphicEntryOffsetAOT = 18; #elif defined(TARGET_ARCH_RISCV64) - static const intptr_t kMonomorphicEntryOffsetJIT = 6; - static const intptr_t kPolymorphicEntryOffsetJIT = 44; - static const intptr_t kMonomorphicEntryOffsetAOT = 6; - static const intptr_t kPolymorphicEntryOffsetAOT = 18; + static constexpr intptr_t kMonomorphicEntryOffsetJIT = 6; + static constexpr intptr_t kPolymorphicEntryOffsetJIT = 44; + static constexpr intptr_t kMonomorphicEntryOffsetAOT = 6; + static constexpr intptr_t kPolymorphicEntryOffsetAOT = 18; #else #error Missing entry offsets for current architecture #endif @@ -5542,7 +5542,7 @@ class Instructions : public Object { return entry; } - static const intptr_t kMaxElements = + static constexpr intptr_t kMaxElements = (kMaxInt32 - (sizeof(UntaggedInstructions) + sizeof(UntaggedObject) + (2 * kObjectStartAlignment))); @@ -5551,11 +5551,11 @@ class Instructions : public Object { // If we later decide to align on larger boundaries to put entries at the // start of cache lines, make sure to account for entry points that are // _not_ at the start of the payload. - static const intptr_t kBarePayloadAlignment = 4; + static constexpr intptr_t kBarePayloadAlignment = 4; // When instructions reside in the heap we align the payloads on word // boundaries. - static const intptr_t kNonBarePayloadAlignment = kWordSize; + static constexpr intptr_t kNonBarePayloadAlignment = kWordSize; // In the precompiled runtime when running in bare instructions mode, // Instructions objects don't exist, just their bare payloads, so we @@ -5775,9 +5775,10 @@ class LocalVarDescriptors : public Object { void GetInfo(intptr_t var_index, UntaggedLocalVarDescriptors::VarInfo* info) const; - static const intptr_t kBytesPerElement = + static constexpr intptr_t kBytesPerElement = sizeof(UntaggedLocalVarDescriptors::VarInfo); - static const intptr_t kMaxElements = UntaggedLocalVarDescriptors::kMaxIndex; + static constexpr intptr_t kMaxElements = + UntaggedLocalVarDescriptors::kMaxIndex; static intptr_t InstanceSize() { ASSERT(sizeof(UntaggedLocalVarDescriptors) == @@ -5805,8 +5806,8 @@ class LocalVarDescriptors : public Object { class PcDescriptors : public Object { public: - static const intptr_t kBytesPerElement = 1; - static const intptr_t kMaxElements = kMaxInt32 / kBytesPerElement; + static constexpr intptr_t kBytesPerElement = 1; + static constexpr intptr_t kMaxElements = kMaxInt32 / kBytesPerElement; static intptr_t HeaderSize() { return sizeof(UntaggedPcDescriptors); } static intptr_t UnroundedSize(PcDescriptorsPtr desc) { @@ -5943,8 +5944,8 @@ class PcDescriptors : public Object { class CodeSourceMap : public Object { public: - static const intptr_t kBytesPerElement = 1; - static const intptr_t kMaxElements = kMaxInt32 / kBytesPerElement; + static constexpr intptr_t kBytesPerElement = 1; + static constexpr intptr_t kMaxElements = kMaxInt32 / kBytesPerElement; static intptr_t HeaderSize() { return sizeof(UntaggedCodeSourceMap); } static intptr_t UnroundedSize(CodeSourceMapPtr map) { @@ -6291,7 +6292,7 @@ class CompressedStackMaps : public Object { class ExceptionHandlers : public Object { public: - static const intptr_t kInvalidPcOffset = 0; + static constexpr intptr_t kInvalidPcOffset = 0; intptr_t num_entries() const; @@ -6343,7 +6344,7 @@ class ExceptionHandlers : public Object { // Pick somewhat arbitrary maximum number of exception handlers // for a function. This value is used to catch potentially // malicious code. - static const intptr_t kMaxHandlers = 1024 * 1024; + static constexpr intptr_t kMaxHandlers = 1024 * 1024; void set_handled_types_data(const Array& value) const; @@ -6448,8 +6449,8 @@ class WeakArray : public Object { untag()->set_element(index, value.ptr()); } - static const intptr_t kBytesPerElement = kCompressedWordSize; - static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; + static constexpr intptr_t kBytesPerElement = kCompressedWordSize; + static constexpr intptr_t kMaxElements = kSmiMax / kBytesPerElement; static constexpr bool IsValidLength(intptr_t length) { return 0 <= length && length <= kMaxElements; @@ -6865,9 +6866,9 @@ class Code : public Object { // We would have a VisitPointers function here to traverse all the // embedded objects in the instructions using pointer_offsets. - static const intptr_t kBytesPerElement = + static constexpr intptr_t kBytesPerElement = sizeof(reinterpret_cast(kOffsetOfPtr)->data()[0]); - static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; + static constexpr intptr_t kMaxElements = kSmiMax / kBytesPerElement; struct ArrayTraits { static intptr_t elements_start_offset() { return sizeof(UntaggedCode); } @@ -7032,7 +7033,7 @@ class Code : public Object { DISALLOW_COPY_AND_ASSIGN(SlowFindRawCodeVisitor); }; - static const intptr_t kEntrySize = sizeof(int32_t); // NOLINT + static constexpr intptr_t kEntrySize = sizeof(int32_t); // NOLINT void set_compile_timestamp(int64_t timestamp) const { #if defined(PRODUCT) @@ -7156,8 +7157,8 @@ class Context : public Object { void Dump(int indent = 0) const; - static const intptr_t kBytesPerElement = kCompressedWordSize; - static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; + static constexpr intptr_t kBytesPerElement = kCompressedWordSize; + static constexpr intptr_t kMaxElements = kSmiMax / kBytesPerElement; struct ArrayTraits { static intptr_t elements_start_offset() { return sizeof(UntaggedContext); } @@ -7254,9 +7255,9 @@ class ContextScope : public Object { intptr_t KernelOffsetAt(intptr_t scope_index) const; void SetKernelOffsetAt(intptr_t scope_index, intptr_t kernel_offset) const; - static const intptr_t kBytesPerElement = + static constexpr intptr_t kBytesPerElement = sizeof(UntaggedContextScope::VariableDesc); - static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; + static constexpr intptr_t kMaxElements = kSmiMax / kBytesPerElement; struct ArrayTraits { static intptr_t elements_start_offset() { @@ -7329,9 +7330,9 @@ class Sentinel : public Object { class MegamorphicCache : public CallSiteData { public: - static const intptr_t kInitialCapacity = 16; - static const intptr_t kSpreadFactor = 7; - static const double kLoadFactor; + static constexpr intptr_t kInitialCapacity = 16; + static constexpr intptr_t kSpreadFactor = 7; + static constexpr double kLoadFactor = 0.50; enum EntryType { kClassIdIndex, @@ -7961,8 +7962,8 @@ class LibraryPrefix : public Instance { const Library& importer); private: - static const int kInitialSize = 2; - static const int kIncrementSize = 2; + static constexpr int kInitialSize = 2; + static constexpr int kIncrementSize = 2; void set_name(const String& value) const; void set_imports(const Array& value) const; @@ -8013,13 +8014,13 @@ class TypeParameters : public Object { // The number of flags per Smi should be a power of 2 in order to simplify the // generated code accessing the flags array. #if !defined(DART_COMPRESSED_POINTERS) - static const intptr_t kFlagsPerSmiShift = kBitsPerWordLog2 - 1; + static constexpr intptr_t kFlagsPerSmiShift = kBitsPerWordLog2 - 1; #else - static const intptr_t kFlagsPerSmiShift = kBitsPerWordLog2 - 2; + static constexpr intptr_t kFlagsPerSmiShift = kBitsPerWordLog2 - 2; #endif - static const intptr_t kFlagsPerSmi = 1LL << kFlagsPerSmiShift; + static constexpr intptr_t kFlagsPerSmi = 1LL << kFlagsPerSmiShift; COMPILE_ASSERT(kFlagsPerSmi < kSmiBits); - static const intptr_t kFlagsPerSmiMask = kFlagsPerSmi - 1; + static constexpr intptr_t kFlagsPerSmiMask = kFlagsPerSmi - 1; void Print(Thread* thread, Zone* zone, @@ -8065,7 +8066,7 @@ class TypeParameters : public Object { class TypeArguments : public Instance { public: // Hash value for a type argument vector consisting solely of dynamic types. - static const intptr_t kAllDynamicHash = 1; + static constexpr intptr_t kAllDynamicHash = 1; // Returns whether this TypeArguments vector can be used in a context that // expects a vector of length [count]. Always true for the null vector. @@ -8108,12 +8109,12 @@ class TypeArguments : public Instance { // Note that this allows for ITA to be longer than UTA (the bit vector must be // stored in the same order as the corresponding type vector, i.e. with the // least significant 2 bits representing the nullability of the first type). - static const intptr_t kNullabilityBitsPerType = 2; - static const intptr_t kNullabilityMaxTypes = + static constexpr intptr_t kNullabilityBitsPerType = 2; + static constexpr intptr_t kNullabilityMaxTypes = kSmiBits / kNullabilityBitsPerType; - static const intptr_t kNonNullableBits = 0; - static const intptr_t kNullableBits = 3; - static const intptr_t kLegacyBits = 2; + static constexpr intptr_t kNonNullableBits = 0; + static constexpr intptr_t kNullableBits = 3; + static constexpr intptr_t kLegacyBits = 2; intptr_t nullability() const; static intptr_t nullability_offset() { return OFFSET_OF(UntaggedTypeArguments, nullability_); @@ -8453,8 +8454,8 @@ class TypeArguments : public Instance { return OFFSET_OF(UntaggedTypeArguments, instantiations_); } - static const intptr_t kBytesPerElement = kCompressedWordSize; - static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; + static constexpr intptr_t kBytesPerElement = kCompressedWordSize; + static constexpr intptr_t kMaxElements = kSmiMax / kBytesPerElement; static intptr_t InstanceSize() { ASSERT(sizeof(UntaggedTypeArguments) == @@ -8504,7 +8505,7 @@ class TypeArguments : public Instance { void SetLength(intptr_t value) const; // Number of fields in the raw object is 4: // instantiations_, length_, hash_ and nullability_. - static const int kNumFields = 4; + static constexpr int kNumFields = 4; FINAL_HEAP_OBJECT_IMPLEMENTATION(TypeArguments, Instance); friend class AbstractType; @@ -9578,9 +9579,9 @@ class Integer : public Number { class Smi : public Integer { public: - static const intptr_t kBits = kSmiBits; - static const intptr_t kMaxValue = kSmiMax; - static const intptr_t kMinValue = kSmiMin; + static constexpr intptr_t kBits = kSmiBits; + static constexpr intptr_t kMaxValue = kSmiMax; + static constexpr intptr_t kMinValue = kSmiMin; intptr_t Value() const { return RawSmiValue(ptr()); } @@ -9659,10 +9660,10 @@ class SmiTraits : AllStatic { class Mint : public Integer { public: - static const intptr_t kBits = 63; // 64-th bit is sign. - static const int64_t kMaxValue = + static constexpr intptr_t kBits = 63; // 64-th bit is sign. + static constexpr int64_t kMaxValue = static_cast(DART_2PART_UINT64_C(0x7FFFFFFF, FFFFFFFF)); - static const int64_t kMinValue = + static constexpr int64_t kMinValue = static_cast(DART_2PART_UINT64_C(0x80000000, 00000000)); int64_t value() const { return untag()->value_; } @@ -9752,19 +9753,20 @@ class Symbol : public AllStatic { // String may not be '\0' terminated. class String : public Instance { public: - static const intptr_t kOneByteChar = 1; - static const intptr_t kTwoByteChar = 2; + static constexpr intptr_t kOneByteChar = 1; + static constexpr intptr_t kTwoByteChar = 2; // All strings share the same maximum element count to keep things // simple. We choose a value that will prevent integer overflow for // 2 byte strings, since it is the worst case. #if defined(HASH_IN_OBJECT_HEADER) - static const intptr_t kSizeofRawString = sizeof(UntaggedInstance) + kWordSize; + static constexpr intptr_t kSizeofRawString = + sizeof(UntaggedInstance) + kWordSize; #else - static const intptr_t kSizeofRawString = + static constexpr intptr_t kSizeofRawString = sizeof(UntaggedInstance) + 2 * kWordSize; #endif - static const intptr_t kMaxElements = kSmiMax / kTwoByteChar; + static constexpr intptr_t kMaxElements = kSmiMax / kTwoByteChar; static intptr_t HeaderSize() { return String::kSizeofRawString; } @@ -10158,8 +10160,8 @@ class OneByteString : public AllStatic { } static OneByteStringPtr EscapeSpecialCharacters(const String& str); // We use the same maximum elements for all strings. - static const intptr_t kBytesPerElement = 1; - static const intptr_t kMaxElements = String::kMaxElements; + static constexpr intptr_t kBytesPerElement = 1; + static constexpr intptr_t kMaxElements = String::kMaxElements; struct ArrayTraits { static intptr_t elements_start_offset() { @@ -10298,8 +10300,8 @@ class TwoByteString : public AllStatic { static TwoByteStringPtr EscapeSpecialCharacters(const String& str); // We use the same maximum elements for all strings. - static const intptr_t kBytesPerElement = 2; - static const intptr_t kMaxElements = String::kMaxElements; + static constexpr intptr_t kBytesPerElement = 2; + static constexpr intptr_t kMaxElements = String::kMaxElements; struct ArrayTraits { static intptr_t elements_start_offset() { @@ -10416,8 +10418,8 @@ class ExternalOneByteString : public AllStatic { } // We use the same maximum elements for all strings. - static const intptr_t kBytesPerElement = 1; - static const intptr_t kMaxElements = String::kMaxElements; + static constexpr intptr_t kBytesPerElement = 1; + static constexpr intptr_t kMaxElements = String::kMaxElements; static intptr_t InstanceSize() { return String::RoundedAllocationSize(sizeof(UntaggedExternalOneByteString)); @@ -10509,8 +10511,8 @@ class ExternalTwoByteString : public AllStatic { } // We use the same maximum elements for all strings. - static const intptr_t kBytesPerElement = 2; - static const intptr_t kMaxElements = String::kMaxElements; + static constexpr intptr_t kBytesPerElement = 2; + static constexpr intptr_t kMaxElements = String::kMaxElements; static intptr_t InstanceSize() { return String::RoundedAllocationSize(sizeof(UntaggedExternalTwoByteString)); @@ -10690,7 +10692,7 @@ class Array : public Instance { bool IsImmutable() const { return ptr()->GetClassId() == kImmutableArrayCid; } // Position of element type in type arguments. - static const intptr_t kElementTypeTypeArgPos = 0; + static constexpr intptr_t kElementTypeTypeArgPos = 0; virtual TypeArgumentsPtr GetTypeArguments() const { return untag()->type_arguments(); @@ -10710,9 +10712,9 @@ class Array : public Instance { virtual bool CanonicalizeEquals(const Instance& other) const; virtual uint32_t CanonicalizeHash() const; - static const intptr_t kBytesPerElement = ArrayTraits::kElementSize; - static const intptr_t kMaxElements = kSmiMax / kBytesPerElement; - static const intptr_t kMaxNewSpaceElements = + static constexpr intptr_t kBytesPerElement = ArrayTraits::kElementSize; + static constexpr intptr_t kMaxElements = kSmiMax / kBytesPerElement; + static constexpr intptr_t kMaxNewSpaceElements = (Heap::kNewAllocatableSize - sizeof(UntaggedArray)) / kBytesPerElement; static intptr_t type_arguments_offset() { @@ -10948,7 +10950,7 @@ class GrowableObjectArray : public Instance { private: UntaggedArray* DataArray() const { return data()->untag(); } - static const int kDefaultInitialCapacity = 0; + static constexpr int kDefaultInitialCapacity = 0; FINAL_HEAP_OBJECT_IMPLEMENTATION(GrowableObjectArray, Instance); friend class Array; @@ -11224,8 +11226,8 @@ class Record : public Instance { untag()->set_field(field_index, value.ptr()); } - static const intptr_t kBytesPerElement = kCompressedWordSize; - static const intptr_t kMaxElements = RecordShape::kMaxNumFields; + static constexpr intptr_t kBytesPerElement = kCompressedWordSize; + static constexpr intptr_t kMaxElements = RecordShape::kMaxNumFields; struct ArrayTraits { static intptr_t elements_start_offset() { return sizeof(UntaggedRecord); } @@ -11402,7 +11404,7 @@ class TypedDataBase : public PointerBase { ASSERT(size != 0); return size; } - static const intptr_t kNumElementSizes = + static constexpr intptr_t kNumElementSizes = (kTypedDataFloat64x2ArrayCid - kTypedDataInt8ArrayCid) / 4 + 1; static const intptr_t element_size_table[kNumElementSizes]; @@ -11509,7 +11511,7 @@ class ExternalTypedData : public TypedDataBase { public: // Alignment of data when serializing ExternalTypedData in a clustered // snapshot. Should be independent of word size. - static const int kDataSerializationAlignment = 8; + static constexpr int kDataSerializationAlignment = 8; FinalizablePersistentHandle* AddFinalizer(void* peer, Dart_HandleFinalizer callback, @@ -11680,7 +11682,7 @@ class Pointer : public Instance { return OFFSET_OF(UntaggedPointer, type_arguments_); } - static const intptr_t kNativeTypeArgPos = 0; + static constexpr intptr_t kNativeTypeArgPos = 0; // Fetches the NativeType type argument. AbstractTypePtr type_argument() const { @@ -11833,8 +11835,8 @@ class LinkedHashBase : public Instance { protected: // Keep this in sync with Dart implementation (lib/compact_hash.dart). - static const intptr_t kInitialIndexBits = 2; - static const intptr_t kInitialIndexSize = 1 << (kInitialIndexBits + 1); + static constexpr intptr_t kInitialIndexBits = 2; + static constexpr intptr_t kInitialIndexSize = 1 << (kInitialIndexBits + 1); private: LinkedHashBasePtr ptr() const { return static_cast(ptr_); } @@ -12285,7 +12287,7 @@ class DebuggerStackTrace; // Internal stacktrace object used in exceptions for printing stack traces. class StackTrace : public Instance { public: - static const int kPreallocatedStackdepth = 90; + static constexpr int kPreallocatedStackdepth = 90; intptr_t Length() const; @@ -12448,7 +12450,7 @@ class RegExpFlags { kDotAll = 16, }; - static const int kDefaultFlags = 0; + static constexpr int kDefaultFlags = 0; RegExpFlags() : value_(kDefaultFlags) {} explicit RegExpFlags(int value) : value_(value) {} diff --git a/runtime/vm/object_graph.cc b/runtime/vm/object_graph.cc index dc764b9d524..3243a646694 100644 --- a/runtime/vm/object_graph.cc +++ b/runtime/vm/object_graph.cc @@ -265,8 +265,8 @@ class ObjectGraph::Stack : public ObjectPointerVisitor { bool visit_weak_persistent_handles_ = false; static ObjectPtr* const kSentinel; - static const intptr_t kInitialCapacity = 1024; - static const intptr_t kNoParent = -1; + static constexpr intptr_t kInitialCapacity = 1024; + static constexpr intptr_t kNoParent = -1; intptr_t Parent(intptr_t index) const { // The parent is just below the next sentinel. @@ -1058,7 +1058,7 @@ enum NonReferenceDataTags { kNameData, }; -static const intptr_t kMaxStringElements = 128; +static constexpr intptr_t kMaxStringElements = 128; enum ExtraCids { kRootExtraCid = 1, // 1-origin diff --git a/runtime/vm/object_graph.h b/runtime/vm/object_graph.h index 0761993d785..d96fde2c08f 100644 --- a/runtime/vm/object_graph.h +++ b/runtime/vm/object_graph.h @@ -164,7 +164,7 @@ class VmServiceHeapSnapshotChunkedWriter : public ChunkedWriter { virtual void WriteChunk(uint8_t* buffer, intptr_t size, bool last); private: - static const intptr_t kMetadataReservation = 512; + static constexpr intptr_t kMetadataReservation = 512; }; // Generates a dump of the heap, whose format is described in @@ -243,7 +243,7 @@ class HeapSnapshotWriter : public ThreadStackResource { private: static uint32_t GetHashHelper(Thread* thread, ObjectPtr obj); - static const intptr_t kPreferredChunkSize = MB; + static constexpr intptr_t kPreferredChunkSize = MB; void SetupCountingPages(); bool OnImagePage(ObjectPtr obj) const; @@ -269,7 +269,7 @@ class HeapSnapshotWriter : public ThreadStackResource { }; // There are up to 4 images to consider: // {instructions, data} x {vm isolate, current isolate} - static const intptr_t kMaxImagePages = 4; + static constexpr intptr_t kMaxImagePages = 4; ImagePageRange image_page_ranges_[kMaxImagePages]; MallocGrowableArray smis_; diff --git a/runtime/vm/object_id_ring.h b/runtime/vm/object_id_ring.h index deca92ba330..d94965c12a0 100644 --- a/runtime/vm/object_id_ring.h +++ b/runtime/vm/object_id_ring.h @@ -35,9 +35,9 @@ class ObjectIdRing { kNumIdPolicy, }; - static const int32_t kMaxId = 0x3FFFFFFF; - static const int32_t kInvalidId = -1; - static const int32_t kDefaultCapacity = 8192; + static constexpr int32_t kMaxId = 0x3FFFFFFF; + static constexpr int32_t kInvalidId = -1; + static constexpr int32_t kDefaultCapacity = 8192; ObjectIdRing(); ~ObjectIdRing(); diff --git a/runtime/vm/os_linux.cc b/runtime/vm/os_linux.cc index a2a7a2a5640..f39a31d435d 100644 --- a/runtime/vm/os_linux.cc +++ b/runtime/vm/os_linux.cc @@ -273,11 +273,11 @@ class JitDumpCodeObserver : public CodeObserver { // ELF machine architectures // From linux/include/uapi/linux/elf-em.h - static const uint32_t EM_386 = 3; - static const uint32_t EM_X86_64 = 62; - static const uint32_t EM_ARM = 40; - static const uint32_t EM_AARCH64 = 183; - static const uint32_t EM_RISCV = 243; + static constexpr uint32_t EM_386 = 3; + static constexpr uint32_t EM_X86_64 = 62; + static constexpr uint32_t EM_ARM = 40; + static constexpr uint32_t EM_AARCH64 = 183; + static constexpr uint32_t EM_RISCV = 243; static uint32_t GetElfMachineArchitecture() { #if TARGET_ARCH_IA32 @@ -297,9 +297,9 @@ class JitDumpCodeObserver : public CodeObserver { } #if ARCH_IS_64_BIT - static const int kElfHeaderSize = 0x40; + static constexpr int kElfHeaderSize = 0x40; #else - static const int kElfHeaderSize = 0x34; + static constexpr int kElfHeaderSize = 0x34; #endif void WriteDebugInfo(uword base, const CodeComments* comments) { diff --git a/runtime/vm/os_thread.h b/runtime/vm/os_thread.h index c27b7a940a4..be29c00e640 100644 --- a/runtime/vm/os_thread.h +++ b/runtime/vm/os_thread.h @@ -229,7 +229,7 @@ class OSThread : public BaseThread { static void DisableOSThreadCreation(); static void EnableOSThreadCreation(); - static const intptr_t kStackSizeBufferMax = (16 * KB * kWordSize); + static constexpr intptr_t kStackSizeBufferMax = (16 * KB * kWordSize); static constexpr float kStackSizeBufferFraction = 0.5; static const ThreadId kInvalidThreadId; @@ -340,7 +340,7 @@ class Monitor { public: enum WaitResult { kNotified, kTimedOut }; - static const int64_t kNoTimeout = 0; + static constexpr int64_t kNoTimeout = 0; Monitor(); ~Monitor(); diff --git a/runtime/vm/os_win.cc b/runtime/vm/os_win.cc index 4de8c339113..b3814f1cda5 100644 --- a/runtime/vm/os_win.cc +++ b/runtime/vm/os_win.cc @@ -108,8 +108,8 @@ int64_t OS::GetCurrentTimeMillis() { } int64_t OS::GetCurrentTimeMicros() { - static const int64_t kTimeEpoc = 116444736000000000LL; - static const int64_t kTimeScaler = 10; // 100 ns to us. + const int64_t kTimeEpoc = 116444736000000000LL; + const int64_t kTimeScaler = 10; // 100 ns to us. // Although win32 uses 64-bit integers for representing timestamps, // these are packed into a FILETIME structure. The FILETIME diff --git a/runtime/vm/port_set.h b/runtime/vm/port_set.h index a632f50c5d3..5809f6ac17b 100644 --- a/runtime/vm/port_set.h +++ b/runtime/vm/port_set.h @@ -99,7 +99,7 @@ class PortSet { }; PortSet() { - static const intptr_t kInitialCapacity = 8; + const intptr_t kInitialCapacity = 8; ASSERT(Utils::IsPowerOfTwo(kInitialCapacity)); map_ = new T[kInitialCapacity]; capacity_ = kInitialCapacity; diff --git a/runtime/vm/profiler.cc b/runtime/vm/profiler.cc index 916ba2e4ecb..53074cb5f9c 100644 --- a/runtime/vm/profiler.cc +++ b/runtime/vm/profiler.cc @@ -32,7 +32,7 @@ namespace dart { -static const intptr_t kMaxSamplesPerTick = 4; +static constexpr intptr_t kMaxSamplesPerTick = 4; DEFINE_FLAG(bool, trace_profiled_isolates, false, "Trace profiled isolates."); diff --git a/runtime/vm/profiler.h b/runtime/vm/profiler.h index c00d381cf01..3ea490537b5 100644 --- a/runtime/vm/profiler.h +++ b/runtime/vm/profiler.h @@ -174,7 +174,7 @@ class SampleFilter : public ValueObject { bool take_samples() const { return take_samples_; } - static const intptr_t kNoTaskFilter = -1; + static constexpr intptr_t kNoTaskFilter = -1; private: Dart_Port port_; @@ -650,7 +650,7 @@ class SampleBuffer : public ProcessedSampleBufferBuilder { class SampleBlock : public SampleBuffer { public: // The default number of samples per block. Overridden by some tests. - static const intptr_t kSamplesPerBlock = 100; + static constexpr intptr_t kSamplesPerBlock = 100; SampleBlock() = default; virtual ~SampleBlock() = default; @@ -743,7 +743,7 @@ class SampleBlock : public SampleBuffer { class SampleBlockBuffer : public ProcessedSampleBufferBuilder { public: - static const intptr_t kDefaultBlockCount = 600; + static constexpr intptr_t kDefaultBlockCount = 600; // Creates a SampleBlockBuffer with a predetermined number of blocks. // @@ -942,7 +942,7 @@ class SampleBlockProcessor : public AllStatic { static void Cleanup(); private: - static const intptr_t kMaxThreads = 4096; + static constexpr intptr_t kMaxThreads = 4096; static bool initialized_; static bool shutdown_; static bool thread_running_; diff --git a/runtime/vm/profiler_service.h b/runtime/vm/profiler_service.h index d39125bdf2c..44f3cdc5abf 100644 --- a/runtime/vm/profiler_service.h +++ b/runtime/vm/profiler_service.h @@ -118,7 +118,7 @@ class ProfileCodeInlinedFunctionsCache : public ZoneAllocated { TokenPosition token_position = TokenPosition::kNoSource; }; - static const intptr_t kCacheSize = 128; + static constexpr intptr_t kCacheSize = 128; intptr_t cache_cursor_; intptr_t last_hit_; CacheEntry cache_[kCacheSize]; diff --git a/runtime/vm/profiler_test.cc b/runtime/vm/profiler_test.cc index 9383709e263..164d724885b 100644 --- a/runtime/vm/profiler_test.cc +++ b/runtime/vm/profiler_test.cc @@ -379,7 +379,7 @@ class ProfileStackWalker { return profile_->GetCodeFromPC(pc, timestamp); } - static const intptr_t kInvalidInlinedIndex = -1; + static constexpr intptr_t kInvalidInlinedIndex = -1; bool UpdateFunctionIndex() { if (inlined_index_ != kInvalidInlinedIndex) { diff --git a/runtime/vm/raw_object.h b/runtime/vm/raw_object.h index 4e9df320367..bcd3c1ef0ed 100644 --- a/runtime/vm/raw_object.h +++ b/runtime/vm/raw_object.h @@ -174,9 +174,9 @@ class UntaggedObject { kHashTagSize = 32, }; - static const intptr_t kGenerationalBarrierMask = 1 << kNewBit; - static const intptr_t kIncrementalBarrierMask = 1 << kOldAndNotMarkedBit; - static const intptr_t kBarrierOverlapShift = 2; + static constexpr intptr_t kGenerationalBarrierMask = 1 << kNewBit; + static constexpr intptr_t kIncrementalBarrierMask = 1 << kOldAndNotMarkedBit; + static constexpr intptr_t kBarrierOverlapShift = 2; COMPILE_ASSERT(kOldAndNotMarkedBit + kBarrierOverlapShift == kOldBit); COMPILE_ASSERT(kNewBit + kBarrierOverlapShift == kOldAndNotRememberedBit); @@ -1997,9 +1997,10 @@ class UntaggedPcDescriptors : public UntaggedObject { } private: - static const intptr_t kKindShiftSize = 3; - static const intptr_t kTryIndexSize = 10; - static const intptr_t kYieldIndexSize = 32 - kKindShiftSize - kTryIndexSize; + static constexpr intptr_t kKindShiftSize = 3; + static constexpr intptr_t kTryIndexSize = 10; + static constexpr intptr_t kYieldIndexSize = + 32 - kKindShiftSize - kTryIndexSize; class KindShiftBits : public BitField {}; diff --git a/runtime/vm/regexp.cc b/runtime/vm/regexp.cc index 576e647bfb7..2d78c863462 100644 --- a/runtime/vm/regexp.cc +++ b/runtime/vm/regexp.cc @@ -28,10 +28,10 @@ namespace dart { // Default to generating optimized regexp code. -static const bool kRegexpOptimization = true; +static constexpr bool kRegexpOptimization = true; // More makes code generation slower, less makes V8 benchmark score lower. -static const intptr_t kMaxLookaheadForBoyerMoore = 8; +static constexpr intptr_t kMaxLookaheadForBoyerMoore = 8; ContainedInLattice AddRange(ContainedInLattice containment, const int32_t* ranges, @@ -326,14 +326,14 @@ class RegExpCompiler : public ValueObject { inline void AddWork(RegExpNode* node) { work_list_->Add(node); } - static const intptr_t kImplementationOffset = 0; - static const intptr_t kNumberOfRegistersOffset = 0; - static const intptr_t kCodeOffset = 1; + static constexpr intptr_t kImplementationOffset = 0; + static constexpr intptr_t kNumberOfRegistersOffset = 0; + static constexpr intptr_t kCodeOffset = 1; RegExpMacroAssembler* macro_assembler() { return macro_assembler_; } EndNode* accept() { return accept_; } - static const intptr_t kMaxRecursion = 100; + static constexpr intptr_t kMaxRecursion = 100; inline intptr_t recursion_depth() { return recursion_depth_; } inline void IncrementRecursionDepth() { recursion_depth_++; } inline void DecrementRecursionDepth() { recursion_depth_--; } @@ -352,7 +352,7 @@ class RegExpCompiler : public ValueObject { Zone* zone() const { return zone_; } - static const intptr_t kNoRegister = -1; + static constexpr intptr_t kNoRegister = -1; private: EndNode* accept_; @@ -548,7 +548,7 @@ void Trace::PerformDeferredActions(RegExpMacroAssembler* assembler, intptr_t value = 0; bool absolute = false; bool clear = false; - static const intptr_t kNoStore = kMinInt32; + const intptr_t kNoStore = kMinInt32; intptr_t store_position = kNoStore; // This is a little tricky because we are scanning the actions in reverse // historical order (newest first). @@ -1067,8 +1067,8 @@ static void EmitUseLookupTable(RegExpMacroAssembler* masm, BlockLabel* fall_through, BlockLabel* even_label, BlockLabel* odd_label) { - static const intptr_t kSize = RegExpMacroAssembler::kTableSize; - static const intptr_t kMask = RegExpMacroAssembler::kTableMask; + const intptr_t kSize = RegExpMacroAssembler::kTableSize; + const intptr_t kMask = RegExpMacroAssembler::kTableMask; intptr_t base = (min_char & ~kMask); @@ -1149,8 +1149,8 @@ static void SplitSearchSpace(ZoneGrowableArray* ranges, intptr_t* new_start_index, intptr_t* new_end_index, uint16_t* border) { - static const intptr_t kSize = RegExpMacroAssembler::kTableSize; - static const intptr_t kMask = RegExpMacroAssembler::kTableMask; + const intptr_t kSize = RegExpMacroAssembler::kTableSize; + const intptr_t kMask = RegExpMacroAssembler::kTableMask; uint16_t first = ranges->At(start_index); uint16_t last = ranges->At(end_index) - 1; @@ -1265,7 +1265,7 @@ static void GenerateBranches(RegExpMacroAssembler* masm, // If there are a lot of intervals in the regexp, then we will use tables to // determine whether the character is inside or outside the character class. - static const intptr_t kBits = RegExpMacroAssembler::kTableSizeBits; + const intptr_t kBits = RegExpMacroAssembler::kTableSizeBits; if ((max_char >> kBits) == (min_char >> kBits)) { EmitUseLookupTable(masm, ranges, start_index, end_index, min_char, @@ -2749,7 +2749,7 @@ class AlternativeGenerationList { } private: - static const intptr_t kAFew = 10; + static constexpr intptr_t kAFew = 10; intptr_t count_; AlternativeGeneration a_few_alt_gens_[kAFew]; @@ -2759,28 +2759,28 @@ class AlternativeGenerationList { DISALLOW_COPY_AND_ASSIGN(AlternativeGenerationList); }; -static const int32_t kRangeEndMarker = Utf::kMaxCodePoint + 1; +static constexpr int32_t kRangeEndMarker = Utf::kMaxCodePoint + 1; // The '2' variant is inclusive from and exclusive to. // This covers \s as defined in ECMA-262 5.1, 15.10.2.12, // which include WhiteSpace (7.2) or LineTerminator (7.3) values. // 0x180E has been removed from Unicode's Zs category and thus // from ECMAScript's WhiteSpace category as of Unicode 6.3. -static const int32_t kSpaceRanges[] = { +static constexpr int32_t kSpaceRanges[] = { '\t', '\r' + 1, ' ', ' ' + 1, 0x00A0, 0x00A1, 0x1680, 0x1681, 0x2000, 0x200B, 0x2028, 0x202A, 0x202F, 0x2030, 0x205F, 0x2060, 0x3000, 0x3001, 0xFEFF, 0xFF00, kRangeEndMarker}; -static const intptr_t kSpaceRangeCount = ARRAY_SIZE(kSpaceRanges); -static const int32_t kWordRanges[] = { +static constexpr intptr_t kSpaceRangeCount = ARRAY_SIZE(kSpaceRanges); +static constexpr int32_t kWordRanges[] = { '0', '9' + 1, 'A', 'Z' + 1, '_', '_' + 1, 'a', 'z' + 1, kRangeEndMarker}; -static const intptr_t kWordRangeCount = ARRAY_SIZE(kWordRanges); -static const int32_t kDigitRanges[] = {'0', '9' + 1, kRangeEndMarker}; -static const intptr_t kDigitRangeCount = ARRAY_SIZE(kDigitRanges); -static const int32_t kSurrogateRanges[] = {0xd800, 0xe000, kRangeEndMarker}; -static const intptr_t kSurrogateRangeCount = ARRAY_SIZE(kSurrogateRanges); -static const int32_t kLineTerminatorRanges[] = { +static constexpr intptr_t kWordRangeCount = ARRAY_SIZE(kWordRanges); +static constexpr int32_t kDigitRanges[] = {'0', '9' + 1, kRangeEndMarker}; +static constexpr intptr_t kDigitRangeCount = ARRAY_SIZE(kDigitRanges); +static constexpr int32_t kSurrogateRanges[] = {0xd800, 0xe000, kRangeEndMarker}; +static constexpr intptr_t kSurrogateRangeCount = ARRAY_SIZE(kSurrogateRanges); +static constexpr int32_t kLineTerminatorRanges[] = { 0x000A, 0x000B, 0x000D, 0x000E, 0x2028, 0x202A, kRangeEndMarker}; -static const intptr_t kLineTerminatorRangeCount = +static constexpr intptr_t kLineTerminatorRangeCount = ARRAY_SIZE(kLineTerminatorRanges); void BoyerMoorePositionInfo::Set(intptr_t character) { @@ -2863,7 +2863,7 @@ intptr_t BoyerMooreLookahead::FindBestInterval(intptr_t max_number_of_chars, intptr_t* from, intptr_t* to) { intptr_t biggest_points = old_biggest_points; - static const intptr_t kSize = RegExpMacroAssembler::kTableSize; + static constexpr intptr_t kSize = RegExpMacroAssembler::kTableSize; for (intptr_t i = 0; i < length_;) { while (i < length_ && Count(i) > max_number_of_chars) i++; @@ -4220,7 +4220,7 @@ RegExpNode* RegExpQuantifier::ToNode(RegExpCompiler* compiler, // regexp graph generator. class RegExpExpansionLimiter : public ValueObject { public: - static const intptr_t kMaxExpansionFactor = 6; + static constexpr intptr_t kMaxExpansionFactor = 6; RegExpExpansionLimiter(RegExpCompiler* compiler, intptr_t factor) : compiler_(compiler), saved_expansion_factor_(compiler->current_expansion_factor()), @@ -4281,9 +4281,9 @@ RegExpNode* RegExpQuantifier::ToNode(intptr_t min, // from step 2.1. If the min and max are small we can unroll a little in // this case. // Unroll (foo)+ and (foo){3,} - static const intptr_t kMaxUnrolledMinMatches = 3; + const intptr_t kMaxUnrolledMinMatches = 3; // Unroll (foo)? and (foo){x,3} - static const intptr_t kMaxUnrolledMaxMatches = 3; + const intptr_t kMaxUnrolledMaxMatches = 3; if (max == 0) return on_success; // This can happen due to recursion. bool body_can_be_empty = (body->min_match() == 0); intptr_t body_start_reg = RegExpCompiler::kNoRegister; @@ -5383,7 +5383,7 @@ RegExpEngine::CompilationResult RegExpEngine::CompileIR( // Inserted here, instead of in Assembler, because it depends on information // in the AST that isn't replicated in the Node structure. - static const intptr_t kMaxBacksearchLimit = 1024; + const intptr_t kMaxBacksearchLimit = 1024; if (is_end_anchored && !is_start_anchored && !is_sticky && max_length < kMaxBacksearchLimit) { macro_assembler->SetCurrentPositionFromEnd(max_length); @@ -5493,7 +5493,7 @@ RegExpEngine::CompilationResult RegExpEngine::CompileBytecode( // Inserted here, instead of in Assembler, because it depends on information // in the AST that isn't replicated in the Node structure. - static const intptr_t kMaxBacksearchLimit = 1024; + const intptr_t kMaxBacksearchLimit = 1024; if (is_end_anchored && !is_start_anchored && !is_sticky && max_length < kMaxBacksearchLimit) { macro_assembler->SetCurrentPositionFromEnd(max_length); diff --git a/runtime/vm/regexp.h b/runtime/vm/regexp.h index 527058dcdc7..d8d0feb3232 100644 --- a/runtime/vm/regexp.h +++ b/runtime/vm/regexp.h @@ -77,8 +77,8 @@ class CharacterRange { // Negate the contents of a character range in canonical form. static void Negate(ZoneGrowableArray* src, ZoneGrowableArray* dst); - static const intptr_t kStartMarker = (1 << 24); - static const intptr_t kPayloadMask = (1 << 24) - 1; + static constexpr intptr_t kStartMarker = (1 << 24); + static constexpr intptr_t kPayloadMask = (1 << 24) - 1; private: int32_t from_; @@ -94,7 +94,7 @@ class OutSet : public ZoneAllocated { OutSet() : first_(0), remaining_(nullptr), successors_(nullptr) {} OutSet* Extend(unsigned value, Zone* zone); bool Get(unsigned value) const; - static const unsigned kFirstLimit = 32; + static constexpr unsigned kFirstLimit = 32; private: // Destructively set a value in this set. In most cases you want @@ -192,12 +192,12 @@ class UnicodeRangeSplitter : public ValueObject { ZoneGrowableArray* non_bmp() const { return non_bmp_; } private: - static const int kBase = 0; + static constexpr int kBase = 0; // Separate ranges into - static const int kBmpCodePoints = 1; - static const int kLeadSurrogates = 2; - static const int kTrailSurrogates = 3; - static const int kNonBmpCodePoints = 4; + static constexpr int kBmpCodePoints = 1; + static constexpr int kLeadSurrogates = 2; + static constexpr int kTrailSurrogates = 3; + static constexpr int kNonBmpCodePoints = 4; Zone* zone_; ChoiceTable table_; @@ -419,7 +419,7 @@ class RegExpNode : public ZoneAllocated { RegExpCompiler* compiler, intptr_t characters_filled_in, bool not_at_start) = 0; - static const intptr_t kNodeIsTooComplexForGreedyLoops = -1; + static constexpr intptr_t kNodeIsTooComplexForGreedyLoops = -1; virtual intptr_t GreedyLoopTextLength() { return kNodeIsTooComplexForGreedyLoops; } @@ -435,7 +435,7 @@ class RegExpNode : public ZoneAllocated { // implementation. TODO(erikcorry): This should share more code with // EatsAtLeast, GetQuickCheckDetails. The budget argument is used to limit // the number of nodes we are willing to look at in order to create this data. - static const intptr_t kRecursionBudget = 200; + static constexpr intptr_t kRecursionBudget = 200; virtual void FillInBMInfo(intptr_t offset, intptr_t budget, BoyerMooreLookahead* bm, @@ -472,7 +472,7 @@ class RegExpNode : public ZoneAllocated { // on how often we allow that to happen before we insist on starting a new // trace and generating generic code for a node that can be reused by flushing // the deferred actions in the current trace and generating a goto. - static const intptr_t kMaxCopiesCodeGenerated = 10; + static constexpr intptr_t kMaxCopiesCodeGenerated = 10; NodeInfo* info() { return &info_; } @@ -493,7 +493,7 @@ class RegExpNode : public ZoneAllocated { } private: - static const intptr_t kFirstCharBudget = 10; + static constexpr intptr_t kFirstCharBudget = 10; BlockLabel label_; NodeInfo info_; // This variable keeps track of how many times code has been generated for @@ -528,7 +528,7 @@ class Interval { intptr_t from() const { return from_; } intptr_t to() const { return to_; } static Interval Empty() { return Interval(); } - static const intptr_t kNone = -1; + static constexpr intptr_t kNone = -1; private: intptr_t from_; @@ -705,8 +705,8 @@ class TextNode : public SeqRegExpNode { CHARACTER_CLASS_MATCH // Character class. }; static bool SkipPass(intptr_t pass, bool ignore_case); - static const intptr_t kFirstRealPass = SIMPLE_CHARACTER_MATCH; - static const intptr_t kLastPass = CHARACTER_CLASS_MATCH; + static constexpr intptr_t kFirstRealPass = SIMPLE_CHARACTER_MATCH; + static constexpr intptr_t kLastPass = CHARACTER_CLASS_MATCH; void TextEmitPass(RegExpCompiler* compiler, TextEmitPassType pass, bool preloaded, @@ -1109,8 +1109,8 @@ class BoyerMoorePositionInfo : public ZoneAllocated { bool& at(intptr_t i) { return (*map_)[i]; } - static const intptr_t kMapSize = 128; - static const intptr_t kMask = kMapSize - 1; + static constexpr intptr_t kMapSize = 128; + static constexpr intptr_t kMask = kMapSize - 1; intptr_t map_count() const { return map_count_; } @@ -1371,7 +1371,7 @@ class GreedyLoopState { }; struct PreloadState { - static const intptr_t kEatsAtLeastNotYetInitialized = -1; + static constexpr intptr_t kEatsAtLeastNotYetInitialized = -1; bool preload_is_current_; bool preload_has_checked_bounds_; intptr_t preload_characters_; diff --git a/runtime/vm/regexp_assembler.h b/runtime/vm/regexp_assembler.h index 0f5d42805d2..d2482c2f0a0 100644 --- a/runtime/vm/regexp_assembler.h +++ b/runtime/vm/regexp_assembler.h @@ -96,13 +96,13 @@ class BlockLabel : public ValueObject { class RegExpMacroAssembler : public ZoneAllocated { public: // The implementation must be able to handle at least: - static const intptr_t kMaxRegister = (1 << 16) - 1; - static const intptr_t kMaxCPOffset = (1 << 15) - 1; - static const intptr_t kMinCPOffset = -(1 << 15); + static constexpr intptr_t kMaxRegister = (1 << 16) - 1; + static constexpr intptr_t kMaxCPOffset = (1 << 15) - 1; + static constexpr intptr_t kMinCPOffset = -(1 << 15); - static const intptr_t kTableSizeBits = 7; - static const intptr_t kTableSize = 1 << kTableSizeBits; - static const intptr_t kTableMask = kTableSize - 1; + static constexpr intptr_t kTableSizeBits = 7; + static constexpr intptr_t kTableSize = 1 << kTableSizeBits; + static constexpr intptr_t kTableMask = kTableSize - 1; enum { kParamRegExpIndex = 0, diff --git a/runtime/vm/regexp_assembler_bytecode.h b/runtime/vm/regexp_assembler_bytecode.h index c99faa7b4e5..c8c87af40c9 100644 --- a/runtime/vm/regexp_assembler_bytecode.h +++ b/runtime/vm/regexp_assembler_bytecode.h @@ -136,7 +136,7 @@ class BytecodeRegExpMacroAssembler : public RegExpMacroAssembler { intptr_t advance_current_offset_; intptr_t advance_current_end_; - static const int kInvalidPC = -1; + static constexpr int kInvalidPC = -1; DISALLOW_IMPLICIT_CONSTRUCTORS(BytecodeRegExpMacroAssembler); }; diff --git a/runtime/vm/regexp_ast.h b/runtime/vm/regexp_ast.h index d846998d353..b040d50d8fb 100644 --- a/runtime/vm/regexp_ast.h +++ b/runtime/vm/regexp_ast.h @@ -36,7 +36,7 @@ class RegExpVisitor : public ValueObject { class RegExpTree : public ZoneAllocated { public: - static const intptr_t kInfinity = kMaxInt32; + static constexpr intptr_t kInfinity = kMaxInt32; virtual ~RegExpTree() {} virtual void* Accept(RegExpVisitor* visitor, void* data) = 0; virtual RegExpNode* ToNode(RegExpCompiler* compiler, diff --git a/runtime/vm/regexp_bytecodes.h b/runtime/vm/regexp_bytecodes.h index 178c9500318..e85a33578b0 100644 --- a/runtime/vm/regexp_bytecodes.h +++ b/runtime/vm/regexp_bytecodes.h @@ -71,12 +71,13 @@ V(SET_CURRENT_POSITION_FROM_END, 51, 4) /* bc8 idx24 */ // clang-format on -#define DECLARE_BYTECODES(name, code, length) static const int BC_##name = code; +#define DECLARE_BYTECODES(name, code, length) \ + static constexpr int BC_##name = code; BYTECODE_ITERATOR(DECLARE_BYTECODES) #undef DECLARE_BYTECODES #define DECLARE_BYTECODE_LENGTH(name, code, length) \ - static const int BC_##name##_LENGTH = length; + static constexpr int BC_##name##_LENGTH = length; BYTECODE_ITERATOR(DECLARE_BYTECODE_LENGTH) #undef DECLARE_BYTECODE_LENGTH diff --git a/runtime/vm/regexp_interpreter.cc b/runtime/vm/regexp_interpreter.cc index 2b0022809b0..4fed40c9408 100644 --- a/runtime/vm/regexp_interpreter.cc +++ b/runtime/vm/regexp_interpreter.cc @@ -166,7 +166,7 @@ class BacktrackStack { intptr_t max_size() const { return kBacktrackStackSize; } private: - static const intptr_t kBacktrackStackSize = 1 << 16; + static constexpr intptr_t kBacktrackStackSize = 1 << 16; std::unique_ptr memory_; diff --git a/runtime/vm/regexp_parser.cc b/runtime/vm/regexp_parser.cc index bc0bf7182e3..c9f9d4e4796 100644 --- a/runtime/vm/regexp_parser.cc +++ b/runtime/vm/regexp_parser.cc @@ -17,7 +17,7 @@ namespace dart { #define Z zone() // Enables possessive quantifier syntax for testing. -static const bool FLAG_regexp_possessive_quantifier = false; +static constexpr bool FLAG_regexp_possessive_quantifier = false; RegExpBuilder::RegExpBuilder(RegExpFlags flags) : zone_(Thread::Current()->zone()), diff --git a/runtime/vm/regexp_parser.h b/runtime/vm/regexp_parser.h index 1aed648693b..9ccd672fea5 100644 --- a/runtime/vm/regexp_parser.h +++ b/runtime/vm/regexp_parser.h @@ -41,7 +41,7 @@ class RegExpBuilder : public ZoneAllocated { bool is_dot_all() const { return flags_.IsDotAll(); } private: - static const uint16_t kNoPendingSurrogate = 0; + static constexpr uint16_t kNoPendingSurrogate = 0; void AddLeadSurrogate(uint16_t lead_surrogate); void AddTrailSurrogate(uint16_t trail_surrogate); void FlushPendingSurrogate(); @@ -142,8 +142,8 @@ class RegExpParser : public ValueObject { static bool IsSyntaxCharacterOrSlash(uint32_t c); - static const intptr_t kMaxCaptures = 1 << 16; - static const uint32_t kEndMarker = (1 << 21); + static constexpr intptr_t kMaxCaptures = 1 << 16; + static constexpr uint32_t kEndMarker = (1 << 21); private: enum SubexpressionType { diff --git a/runtime/vm/report.h b/runtime/vm/report.h index 3af8573ad23..f9edee58e49 100644 --- a/runtime/vm/report.h +++ b/runtime/vm/report.h @@ -26,8 +26,8 @@ class Report : AllStatic { kBailout, }; - static const bool AtLocation = false; - static const bool AfterLocation = true; + static constexpr bool AtLocation = false; + static constexpr bool AfterLocation = true; // Report an already formatted error via a long jump. DART_NORETURN static void LongJump(const Error& error); diff --git a/runtime/vm/ring_buffer.h b/runtime/vm/ring_buffer.h index a8079b5c0d3..5aa9329a9df 100644 --- a/runtime/vm/ring_buffer.h +++ b/runtime/vm/ring_buffer.h @@ -30,7 +30,7 @@ class RingBuffer { } private: - static const int kMask = N - 1; + static constexpr int kMask = N - 1; COMPILE_ASSERT((N & kMask) == 0); T data_[N]; int64_t count_; diff --git a/runtime/vm/runtime_entry.cc b/runtime/vm/runtime_entry.cc index cdd7a28705d..ab866850cee 100644 --- a/runtime/vm/runtime_entry.cc +++ b/runtime/vm/runtime_entry.cc @@ -3347,8 +3347,8 @@ static void DeoptimizeLastDartFrameIfOptimized() { } #if !defined(DART_PRECOMPILED_RUNTIME) -static const intptr_t kNumberOfSavedCpuRegisters = kNumberOfCpuRegisters; -static const intptr_t kNumberOfSavedFpuRegisters = kNumberOfFpuRegisters; +static constexpr intptr_t kNumberOfSavedCpuRegisters = kNumberOfCpuRegisters; +static constexpr intptr_t kNumberOfSavedFpuRegisters = kNumberOfFpuRegisters; static void CopySavedRegisters(uword saved_registers_address, fpu_register_t** fpu_registers, diff --git a/runtime/vm/scopes.cc b/runtime/vm/scopes.cc index 29e3f4d34b5..bee4a03e6c4 100644 --- a/runtime/vm/scopes.cc +++ b/runtime/vm/scopes.cc @@ -575,7 +575,7 @@ void LocalScope::CaptureLocalVariables(LocalScope* top_scope) { } ContextScopePtr LocalScope::CreateImplicitClosureScope(const Function& func) { - static const intptr_t kNumCapturedVars = 1; + const intptr_t kNumCapturedVars = 1; // Create a ContextScope with space for kNumCapturedVars descriptors. const ContextScope& context_scope = diff --git a/runtime/vm/scopes.h b/runtime/vm/scopes.h index afebc62b6ba..a885b61cc04 100644 --- a/runtime/vm/scopes.h +++ b/runtime/vm/scopes.h @@ -56,7 +56,7 @@ class Slot; // builder and they refer to indices into context objects. class VariableIndex { public: - static const int kInvalidIndex = std::numeric_limits::min(); + static constexpr int kInvalidIndex = std::numeric_limits::min(); explicit VariableIndex(int value = kInvalidIndex) : value_(value) {} @@ -222,7 +222,7 @@ class LocalVariable : public ZoneAllocated { kExplicit, }; - static const int kUninitializedIndex = INT_MIN; + static constexpr int kUninitializedIndex = INT_MIN; static bool IsFilteredIdentifier(const String& name); @@ -430,7 +430,7 @@ class LocalScope : public ZoneAllocated { void CollectLocalVariables(LocalVarDescriptorsBuilder* vars, int16_t* scope_id); - static const int kUninitializedContextLevel = INT_MIN; + static constexpr int kUninitializedContextLevel = INT_MIN; LocalScope* parent_; LocalScope* child_; LocalScope* sibling_; diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc index 5eb3fe4cc0f..e33829db103 100644 --- a/runtime/vm/service.cc +++ b/runtime/vm/service.cc @@ -2111,12 +2111,12 @@ static ObjectPtr LookupHeapObjectCode(char** parts, int num_parts) { return Object::sentinel().ptr(); } uword pc; - static const char* const kCollectedPrefix = "collected-"; - static intptr_t kCollectedPrefixLen = strlen(kCollectedPrefix); - static const char* const kNativePrefix = "native-"; - static const intptr_t kNativePrefixLen = strlen(kNativePrefix); - static const char* const kReusedPrefix = "reused-"; - static const intptr_t kReusedPrefixLen = strlen(kReusedPrefix); + const char* const kCollectedPrefix = "collected-"; + const intptr_t kCollectedPrefixLen = strlen(kCollectedPrefix); + const char* const kNativePrefix = "native-"; + const intptr_t kNativePrefixLen = strlen(kNativePrefix); + const char* const kReusedPrefix = "reused-"; + const intptr_t kReusedPrefixLen = strlen(kReusedPrefix); const char* id = parts[1]; if (strncmp(kCollectedPrefix, id, kCollectedPrefixLen) == 0) { if (!GetUnsignedIntegerId(&id[kCollectedPrefixLen], &pc, 16)) { diff --git a/runtime/vm/simulator_arm.h b/runtime/vm/simulator_arm.h index 7e106a398f4..48d554eb780 100644 --- a/runtime/vm/simulator_arm.h +++ b/runtime/vm/simulator_arm.h @@ -34,7 +34,7 @@ typedef struct { class Simulator { public: - static const uword kSimulatorStackUnderflowSize = 64; + static constexpr uword kSimulatorStackUnderflowSize = 64; Simulator(); ~Simulator(); @@ -120,12 +120,12 @@ class Simulator { private: // Known bad pc value to ensure that the simulator does not execute // without being properly setup. - static const uword kBadLR = -1; + static constexpr uword kBadLR = -1; // A pc value used to signal the simulator to stop execution. Generally // the lr is set to this value on transition from native C code to // simulated execution, so that the simulator can "return" to the native // C code. - static const uword kEndSimulatingPC = -2; + static constexpr uword kEndSimulatingPC = -2; // CPU state. int32_t registers_[kNumberOfCpuRegisters]; diff --git a/runtime/vm/simulator_arm64.h b/runtime/vm/simulator_arm64.h index 0c0e49c3300..dc1484ec9e4 100644 --- a/runtime/vm/simulator_arm64.h +++ b/runtime/vm/simulator_arm64.h @@ -34,7 +34,7 @@ typedef struct { class Simulator { public: - static const uword kSimulatorStackUnderflowSize = 64; + static constexpr uword kSimulatorStackUnderflowSize = 64; Simulator(); ~Simulator(); @@ -116,12 +116,12 @@ class Simulator { private: // Known bad pc value to ensure that the simulator does not execute // without being properly setup. - static const uword kBadLR = -1; + static constexpr uword kBadLR = -1; // A pc value used to signal the simulator to stop execution. Generally // the lr is set to this value on transition from native C code to // simulated execution, so that the simulator can "return" to the native // C code. - static const uword kEndSimulatingPC = -2; + static constexpr uword kEndSimulatingPC = -2; // CPU state. int64_t registers_[kNumberOfCpuRegisters]; diff --git a/runtime/vm/simulator_riscv.h b/runtime/vm/simulator_riscv.h index c4e9136bd30..81332a2359c 100644 --- a/runtime/vm/simulator_riscv.h +++ b/runtime/vm/simulator_riscv.h @@ -23,7 +23,7 @@ class Thread; // TODO(riscv): Dynamic rounding mode and other FSCR state. class Simulator { public: - static const uword kSimulatorStackUnderflowSize = 64; + static constexpr uword kSimulatorStackUnderflowSize = 64; Simulator(); ~Simulator(); diff --git a/runtime/vm/simulator_x64.h b/runtime/vm/simulator_x64.h index dad98f22347..9969d28d7e7 100644 --- a/runtime/vm/simulator_x64.h +++ b/runtime/vm/simulator_x64.h @@ -18,7 +18,7 @@ class Thread; class Simulator { public: - static const uword kSimulatorStackUnderflowSize = 64; + static constexpr uword kSimulatorStackUnderflowSize = 64; Simulator(); ~Simulator(); diff --git a/runtime/vm/snapshot.h b/runtime/vm/snapshot.h index 6499742d4b6..2236b7a986e 100644 --- a/runtime/vm/snapshot.h +++ b/runtime/vm/snapshot.h @@ -33,14 +33,14 @@ class Snapshot { static const Snapshot* SetupFromBuffer(const void* raw_memory); - static const int32_t kMagicValue = 0xdcdcf5f5; - static const intptr_t kMagicOffset = 0; - static const intptr_t kMagicSize = sizeof(int32_t); - static const intptr_t kLengthOffset = kMagicOffset + kMagicSize; - static const intptr_t kLengthSize = sizeof(int64_t); - static const intptr_t kKindOffset = kLengthOffset + kLengthSize; - static const intptr_t kKindSize = sizeof(int64_t); - static const intptr_t kHeaderSize = kKindOffset + kKindSize; + static constexpr int32_t kMagicValue = 0xdcdcf5f5; + static constexpr intptr_t kMagicOffset = 0; + static constexpr intptr_t kMagicSize = sizeof(int32_t); + static constexpr intptr_t kLengthOffset = kMagicOffset + kMagicSize; + static constexpr intptr_t kLengthSize = sizeof(int64_t); + static constexpr intptr_t kKindOffset = kLengthOffset + kLengthSize; + static constexpr intptr_t kKindSize = sizeof(int64_t); + static constexpr intptr_t kHeaderSize = kKindOffset + kKindSize; // Accessors. bool check_magic() const { diff --git a/runtime/vm/snapshot_test.cc b/runtime/vm/snapshot_test.cc index 2d2f77a1dc4..b71d15e945f 100644 --- a/runtime/vm/snapshot_test.cc +++ b/runtime/vm/snapshot_test.cc @@ -963,7 +963,7 @@ VM_UNIT_TEST_CASE(DartGeneratedMessages) { VM_UNIT_TEST_CASE(DartGeneratedListMessages) { const int kArrayLength = 10; - static const char* kScriptChars = + const char* kScriptChars = "final int kArrayLength = 10;\n" "getList() {\n" " return List.filled(kArrayLength, null);\n" @@ -1073,7 +1073,7 @@ VM_UNIT_TEST_CASE(DartGeneratedListMessages) { VM_UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) { const int kArrayLength = 10; - static const char* kScriptChars = + const char* kScriptChars = "final int kArrayLength = 10;\n" "getList() {\n" " return [null, null, null, null, null, null, null, null, null, null];\n" @@ -1293,7 +1293,7 @@ VM_UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) { VM_UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { const int kArrayLength = 10; - static const char* kScriptChars = + const char* kScriptChars = "import 'dart:typed_data';\n" "final int kArrayLength = 10;\n" "getStringList() {\n" @@ -1486,7 +1486,7 @@ VM_UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { VM_UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) { const int kArrayLength = 10; - static const char* kScriptChars = + const char* kScriptChars = "import 'dart:typed_data';\n" "final int kArrayLength = 10;\n" "getStringList() {\n" @@ -1985,7 +1985,7 @@ VM_UNIT_TEST_CASE(PostCObject) { object.value.as_array.length = 0; EXPECT(Dart_PostCObject(port_id, &object)); - static const int kArrayLength = 10; + const int kArrayLength = 10; Dart_CObject* array = reinterpret_cast(Dart_ScopeAllocate( sizeof(Dart_CObject) + sizeof(Dart_CObject*) * kArrayLength)); // NOLINT array->type = Dart_CObject_kArray; diff --git a/runtime/vm/stack_frame.h b/runtime/vm/stack_frame.h index 56a95100f2d..e45428a8c3b 100644 --- a/runtime/vm/stack_frame.h +++ b/runtime/vm/stack_frame.h @@ -424,7 +424,7 @@ DART_FORCE_INLINE static bool IsCalleeFrameOf(uword fp, uword other_fp) { } // Value for stack limit that is used to cause an interrupt. -static const uword kInterruptStackLimit = ~static_cast(0); +static constexpr uword kInterruptStackLimit = ~static_cast(0); DART_FORCE_INLINE static uword LocalVarAddress(uword fp, intptr_t index) { return fp + LocalVarIndex(0, index) * kWordSize; diff --git a/runtime/vm/stack_frame_arm.h b/runtime/vm/stack_frame_arm.h index afdc95167d7..03edc77e919 100644 --- a/runtime/vm/stack_frame_arm.h +++ b/runtime/vm/stack_frame_arm.h @@ -33,28 +33,29 @@ Caller frame | last parameter | <- SP of caller frame T against a slot indicates it needs to be traversed during GC. */ -static const int kDartFrameFixedSize = 4; // PP, FP, LR, PC marker. -static const int kSavedPcSlotFromSp = -1; +static constexpr int kDartFrameFixedSize = 4; // PP, FP, LR, PC marker. +static constexpr int kSavedPcSlotFromSp = -1; -static const int kFirstObjectSlotFromFp = -1; // Used by GC to traverse stack. -static const int kLastFixedObjectSlotFromFp = -2; +static constexpr int kFirstObjectSlotFromFp = + -1; // Used by GC to traverse stack. +static constexpr int kLastFixedObjectSlotFromFp = -2; -static const int kFirstLocalSlotFromFp = -3; -static const int kSavedCallerPpSlotFromFp = -2; -static const int kPcMarkerSlotFromFp = -1; -static const int kSavedCallerFpSlotFromFp = 0; -static const int kSavedCallerPcSlotFromFp = 1; -static const int kParamEndSlotFromFp = 1; // One slot past last parameter. -static const int kCallerSpSlotFromFp = 2; -static const int kLastParamSlotFromEntrySp = 0; +static constexpr int kFirstLocalSlotFromFp = -3; +static constexpr int kSavedCallerPpSlotFromFp = -2; +static constexpr int kPcMarkerSlotFromFp = -1; +static constexpr int kSavedCallerFpSlotFromFp = 0; +static constexpr int kSavedCallerPcSlotFromFp = 1; +static constexpr int kParamEndSlotFromFp = 1; // One slot past last parameter. +static constexpr int kCallerSpSlotFromFp = 2; +static constexpr int kLastParamSlotFromEntrySp = 0; // Entry and exit frame layout. #if defined(DART_TARGET_OS_MACOS) || defined(DART_TARGET_OS_MACOS_IOS) -static const int kExitLinkSlotFromEntryFp = -27; +static constexpr int kExitLinkSlotFromEntryFp = -27; COMPILE_ASSERT(kAbiPreservedCpuRegCount == 6); COMPILE_ASSERT(kAbiPreservedFpuRegCount == 4); #else -static const int kExitLinkSlotFromEntryFp = -28; +static constexpr int kExitLinkSlotFromEntryFp = -28; COMPILE_ASSERT(kAbiPreservedCpuRegCount == 7); COMPILE_ASSERT(kAbiPreservedFpuRegCount == 4); #endif @@ -75,7 +76,7 @@ constexpr intptr_t kCallbackSlotsBeforeSavedArguments = 2; // // [fp] holds callers fp, [fp+4] holds callers lr, [fp+8] is space for // return address, [fp+12] is our pushed TypedData pointer. -static const int kFfiCallerTypedDataSlotFromFp = kCallerSpSlotFromFp + 1; +static constexpr int kFfiCallerTypedDataSlotFromFp = kCallerSpSlotFromFp + 1; } // namespace dart diff --git a/runtime/vm/stack_frame_arm64.h b/runtime/vm/stack_frame_arm64.h index 276a2b949ca..a7a4f73cff9 100644 --- a/runtime/vm/stack_frame_arm64.h +++ b/runtime/vm/stack_frame_arm64.h @@ -32,28 +32,29 @@ Caller frame | last parameter | <- SP of caller frame T against a slot indicates it needs to be traversed during GC. */ -static const int kDartFrameFixedSize = 4; // PP, FP, LR, PC marker. -static const int kSavedPcSlotFromSp = -1; +static constexpr int kDartFrameFixedSize = 4; // PP, FP, LR, PC marker. +static constexpr int kSavedPcSlotFromSp = -1; -static const int kFirstObjectSlotFromFp = -1; // Used by GC to traverse stack. -static const int kLastFixedObjectSlotFromFp = -2; +static constexpr int kFirstObjectSlotFromFp = + -1; // Used by GC to traverse stack. +static constexpr int kLastFixedObjectSlotFromFp = -2; -static const int kFirstLocalSlotFromFp = -3; -static const int kSavedCallerPpSlotFromFp = -2; -static const int kPcMarkerSlotFromFp = -1; -static const int kSavedCallerFpSlotFromFp = 0; -static const int kSavedCallerPcSlotFromFp = 1; +static constexpr int kFirstLocalSlotFromFp = -3; +static constexpr int kSavedCallerPpSlotFromFp = -2; +static constexpr int kPcMarkerSlotFromFp = -1; +static constexpr int kSavedCallerFpSlotFromFp = 0; +static constexpr int kSavedCallerPcSlotFromFp = 1; -static const int kParamEndSlotFromFp = 1; // One slot past last parameter. -static const int kCallerSpSlotFromFp = 2; -static const int kLastParamSlotFromEntrySp = 0; +static constexpr int kParamEndSlotFromFp = 1; // One slot past last parameter. +static constexpr int kCallerSpSlotFromFp = 2; +static constexpr int kLastParamSlotFromEntrySp = 0; // Entry and exit frame layout. #if defined(DART_TARGET_OS_FUCHSIA) -static const int kExitLinkSlotFromEntryFp = -24; +static constexpr int kExitLinkSlotFromEntryFp = -24; COMPILE_ASSERT(kAbiPreservedCpuRegCount == 11); #else -static const int kExitLinkSlotFromEntryFp = -23; +static constexpr int kExitLinkSlotFromEntryFp = -23; COMPILE_ASSERT(kAbiPreservedCpuRegCount == 10); #endif COMPILE_ASSERT(kAbiPreservedFpuRegCount == 8); @@ -69,7 +70,7 @@ constexpr intptr_t kCallbackSlotsBeforeSavedArguments = 2; // For FFI calls passing in TypedData, we save it on the stack before entering // a Dart frame. This denotes how to get to the backed up typed data. -static const int kFfiCallerTypedDataSlotFromFp = kCallerSpSlotFromFp; +static constexpr int kFfiCallerTypedDataSlotFromFp = kCallerSpSlotFromFp; } // namespace dart diff --git a/runtime/vm/stack_frame_ia32.h b/runtime/vm/stack_frame_ia32.h index e1d16fe42e6..54c560fca0c 100644 --- a/runtime/vm/stack_frame_ia32.h +++ b/runtime/vm/stack_frame_ia32.h @@ -30,25 +30,26 @@ Caller frame | last parameter | <- ESP of caller frame T against a slot indicates it needs to be traversed during GC. */ -static const int kDartFrameFixedSize = 3; // PC marker, EBP, PC. -static const int kSavedPcSlotFromSp = -1; +static constexpr int kDartFrameFixedSize = 3; // PC marker, EBP, PC. +static constexpr int kSavedPcSlotFromSp = -1; -static const int kFirstObjectSlotFromFp = -1; // Used by GC to traverse stack. -static const int kLastFixedObjectSlotFromFp = -1; +static constexpr int kFirstObjectSlotFromFp = + -1; // Used by GC to traverse stack. +static constexpr int kLastFixedObjectSlotFromFp = -1; -static const int kFirstLocalSlotFromFp = -2; -static const int kPcMarkerSlotFromFp = -1; -static const int kSavedCallerFpSlotFromFp = 0; -static const int kSavedCallerPcSlotFromFp = 1; -static const int kParamEndSlotFromFp = 1; // One slot past last parameter. -static const int kCallerSpSlotFromFp = 2; -static const int kLastParamSlotFromEntrySp = 1; // Skip return address. +static constexpr int kFirstLocalSlotFromFp = -2; +static constexpr int kPcMarkerSlotFromFp = -1; +static constexpr int kSavedCallerFpSlotFromFp = 0; +static constexpr int kSavedCallerPcSlotFromFp = 1; +static constexpr int kParamEndSlotFromFp = 1; // One slot past last parameter. +static constexpr int kCallerSpSlotFromFp = 2; +static constexpr int kLastParamSlotFromEntrySp = 1; // Skip return address. // No pool pointer on IA32 (indicated by aliasing saved fp). -static const int kSavedCallerPpSlotFromFp = kSavedCallerFpSlotFromFp; +static constexpr int kSavedCallerPpSlotFromFp = kSavedCallerFpSlotFromFp; // Entry and exit frame layout. -static const int kExitLinkSlotFromEntryFp = -8; +static constexpr int kExitLinkSlotFromEntryFp = -8; // All arguments are passed on the stack, so none need to be saved. Therefore // there is no frame for holding the saved arguments. @@ -59,7 +60,7 @@ constexpr intptr_t kCallbackSlotsBeforeSavedArguments = 0; // For FFI calls passing in TypedData, we save it on the stack before entering // a Dart frame. This denotes how to get to the backed up typed data. -static const int kFfiCallerTypedDataSlotFromFp = kCallerSpSlotFromFp; +static constexpr int kFfiCallerTypedDataSlotFromFp = kCallerSpSlotFromFp; } // namespace dart diff --git a/runtime/vm/stack_frame_riscv.h b/runtime/vm/stack_frame_riscv.h index ed0a084d461..28483454161 100644 --- a/runtime/vm/stack_frame_riscv.h +++ b/runtime/vm/stack_frame_riscv.h @@ -32,27 +32,28 @@ Caller frame | last parameter | <- SP of caller frame, FP of current frame T against a slot indicates it needs to be traversed during GC. */ -static const int kDartFrameFixedSize = 4; // PP, FP, RA, PC marker. -static const int kSavedPcSlotFromSp = -1; +static constexpr int kDartFrameFixedSize = 4; // PP, FP, RA, PC marker. +static constexpr int kSavedPcSlotFromSp = -1; -static const int kFirstObjectSlotFromFp = -3; // Used by GC to traverse stack. -static const int kLastFixedObjectSlotFromFp = -4; +static constexpr int kFirstObjectSlotFromFp = + -3; // Used by GC to traverse stack. +static constexpr int kLastFixedObjectSlotFromFp = -4; -static const int kFirstLocalSlotFromFp = -5; -static const int kSavedCallerPpSlotFromFp = -4; -static const int kPcMarkerSlotFromFp = -3; -static const int kSavedCallerFpSlotFromFp = -2; -static const int kSavedCallerPcSlotFromFp = -1; +static constexpr int kFirstLocalSlotFromFp = -5; +static constexpr int kSavedCallerPpSlotFromFp = -4; +static constexpr int kPcMarkerSlotFromFp = -3; +static constexpr int kSavedCallerFpSlotFromFp = -2; +static constexpr int kSavedCallerPcSlotFromFp = -1; -static const int kParamEndSlotFromFp = -1; // One slot past last parameter. -static const int kCallerSpSlotFromFp = 0; -static const int kLastParamSlotFromEntrySp = 0; +static constexpr int kParamEndSlotFromFp = -1; // One slot past last parameter. +static constexpr int kCallerSpSlotFromFp = 0; +static constexpr int kLastParamSlotFromEntrySp = 0; // Entry and exit frame layout. #if defined(TARGET_ARCH_RISCV64) -static const int kExitLinkSlotFromEntryFp = -30; +static constexpr int kExitLinkSlotFromEntryFp = -30; #elif defined(TARGET_ARCH_RISCV32) -static const int kExitLinkSlotFromEntryFp = -42; +static constexpr int kExitLinkSlotFromEntryFp = -42; #endif COMPILE_ASSERT(kAbiPreservedCpuRegCount == 11); COMPILE_ASSERT(kAbiPreservedFpuRegCount == 12); @@ -68,7 +69,7 @@ constexpr intptr_t kCallbackSlotsBeforeSavedArguments = 2; // For FFI calls passing in TypedData, we save it on the stack before entering // a Dart frame. This denotes how to get to the backed up typed data. -static const int kFfiCallerTypedDataSlotFromFp = kCallerSpSlotFromFp; +static constexpr int kFfiCallerTypedDataSlotFromFp = kCallerSpSlotFromFp; } // namespace dart diff --git a/runtime/vm/stack_frame_x64.h b/runtime/vm/stack_frame_x64.h index ba71cedb605..f7efece37b1 100644 --- a/runtime/vm/stack_frame_x64.h +++ b/runtime/vm/stack_frame_x64.h @@ -35,27 +35,28 @@ Caller frame | last parameter | <- RSP of caller frame T against a slot indicates it needs to be traversed during GC. */ -static const int kDartFrameFixedSize = 4; // PC marker, RBP, PP, PC. -static const int kSavedPcSlotFromSp = -1; +static constexpr int kDartFrameFixedSize = 4; // PC marker, RBP, PP, PC. +static constexpr int kSavedPcSlotFromSp = -1; -static const int kFirstObjectSlotFromFp = -1; // Used by GC to traverse stack. -static const int kLastFixedObjectSlotFromFp = -2; +static constexpr int kFirstObjectSlotFromFp = + -1; // Used by GC to traverse stack. +static constexpr int kLastFixedObjectSlotFromFp = -2; -static const int kFirstLocalSlotFromFp = -3; -static const int kSavedCallerPpSlotFromFp = -2; -static const int kPcMarkerSlotFromFp = -1; -static const int kSavedCallerFpSlotFromFp = 0; -static const int kSavedCallerPcSlotFromFp = 1; +static constexpr int kFirstLocalSlotFromFp = -3; +static constexpr int kSavedCallerPpSlotFromFp = -2; +static constexpr int kPcMarkerSlotFromFp = -1; +static constexpr int kSavedCallerFpSlotFromFp = 0; +static constexpr int kSavedCallerPcSlotFromFp = 1; -static const int kParamEndSlotFromFp = 1; // One slot past last parameter. -static const int kCallerSpSlotFromFp = 2; -static const int kLastParamSlotFromEntrySp = 1; // Skip return address. +static constexpr int kParamEndSlotFromFp = 1; // One slot past last parameter. +static constexpr int kCallerSpSlotFromFp = 2; +static constexpr int kLastParamSlotFromEntrySp = 1; // Skip return address. // Entry and exit frame layout. #if defined(DART_TARGET_OS_WINDOWS) -static const int kExitLinkSlotFromEntryFp = -33; +static constexpr int kExitLinkSlotFromEntryFp = -33; #else -static const int kExitLinkSlotFromEntryFp = -11; +static constexpr int kExitLinkSlotFromEntryFp = -11; #endif // defined(DART_TARGET_OS_WINDOWS) // For FFI native -> Dart callbacks, the number of stack slots between arguments @@ -70,7 +71,7 @@ constexpr intptr_t kCallbackSlotsBeforeSavedArguments = // For FFI calls passing in TypedData, we save it on the stack before entering // a Dart frame. This denotes how to get to the backed up typed data. -static const int kFfiCallerTypedDataSlotFromFp = kCallerSpSlotFromFp; +static constexpr int kFfiCallerTypedDataSlotFromFp = kCallerSpSlotFromFp; } // namespace dart diff --git a/runtime/vm/symbols.h b/runtime/vm/symbols.h index a275407f340..c1c2e70862c 100644 --- a/runtime/vm/symbols.h +++ b/runtime/vm/symbols.h @@ -556,11 +556,11 @@ class Symbols : public AllStatic { }; // Number of one character symbols being predefined in the predefined_ array. - static const int kNumberOfOneCharCodeSymbols = + static constexpr int kNumberOfOneCharCodeSymbols = (kMaxPredefinedId - kNullCharId); // Offset of Null character which is the predefined character symbol. - static const int kNullCharCodeSymbolOffset = 0; + static constexpr int kNullCharCodeSymbolOffset = 0; static const String& Symbol(intptr_t index) { ASSERT((index > kIllegal) && (index < kMaxPredefinedId)); diff --git a/runtime/vm/tagged_pointer.h b/runtime/vm/tagged_pointer.h index 13e12d7b295..d0666d38135 100644 --- a/runtime/vm/tagged_pointer.h +++ b/runtime/vm/tagged_pointer.h @@ -18,8 +18,12 @@ class IsolateGroup; class UntaggedObject; #define OBJECT_POINTER_CORE_FUNCTIONS(type, ptr) \ - type* operator->() { return this; } \ - const type* operator->() const { return this; } \ + type* operator->() { \ + return this; \ + } \ + const type* operator->() const { \ + return this; \ + } \ bool IsWellFormed() const { \ const uword value = ptr; \ return (value & kSmiTagMask) == 0 || \ @@ -37,8 +41,7 @@ class UntaggedObject; return (addr & kNewObjectAlignmentOffset) == kNewObjectAlignmentOffset; \ } \ bool IsNewObjectMayBeSmi() const { \ - static const uword kNewObjectBits = \ - (kNewObjectAlignmentOffset | kHeapObjectTag); \ + const uword kNewObjectBits = (kNewObjectAlignmentOffset | kHeapObjectTag); \ const uword addr = ptr; \ return (addr & kObjectAlignmentMask) == kNewObjectBits; \ } \ @@ -52,8 +55,7 @@ class UntaggedObject; /* Like !IsHeapObject() || IsOldObject() but compiles to a single branch. */ \ bool IsSmiOrOldObject() const { \ ASSERT(IsWellFormed()); \ - static const uword kNewObjectBits = \ - (kNewObjectAlignmentOffset | kHeapObjectTag); \ + const uword kNewObjectBits = (kNewObjectAlignmentOffset | kHeapObjectTag); \ const uword addr = ptr; \ return (addr & kObjectAlignmentMask) != kNewObjectBits; \ } \ @@ -61,8 +63,7 @@ class UntaggedObject; /* Like !IsHeapObject() || IsNewObject() but compiles to a single branch. */ \ bool IsSmiOrNewObject() const { \ ASSERT(IsWellFormed()); \ - static const uword kOldObjectBits = \ - (kOldObjectAlignmentOffset | kHeapObjectTag); \ + const uword kOldObjectBits = (kOldObjectAlignmentOffset | kHeapObjectTag); \ const uword addr = ptr; \ return (addr & kObjectAlignmentMask) != kOldObjectBits; \ } \ diff --git a/runtime/vm/tags.h b/runtime/vm/tags.h index cce8d2179b4..7276b80911d 100644 --- a/runtime/vm/tags.h +++ b/runtime/vm/tags.h @@ -107,9 +107,9 @@ class VMTagCounters { class UserTags : public AllStatic { public: // UserTag id space: [kUserTagIdOffset, kUserTagIdOffset + kMaxUserTags). - static const intptr_t kMaxUserTags = 256; - static const uword kUserTagIdOffset = 0x4096; - static const uword kDefaultUserTag = kUserTagIdOffset; + static constexpr intptr_t kMaxUserTags = 256; + static constexpr uword kUserTagIdOffset = 0x4096; + static constexpr uword kDefaultUserTag = kUserTagIdOffset; static const char* TagName(uword tag_id); static bool IsUserTag(uword tag_id) { return (tag_id >= kUserTagIdOffset) && diff --git a/runtime/vm/thread_barrier_test.cc b/runtime/vm/thread_barrier_test.cc index 48e40209d43..a91222b274d 100644 --- a/runtime/vm/thread_barrier_test.cc +++ b/runtime/vm/thread_barrier_test.cc @@ -37,8 +37,8 @@ class FuzzTask : public ThreadPool::Task { }; VM_UNIT_TEST_CASE(ThreadBarrier) { - static const intptr_t kNumTasks = 5; - static const intptr_t kNumRounds = 500; + const intptr_t kNumTasks = 5; + const intptr_t kNumRounds = 500; ThreadBarrier* barrier = new ThreadBarrier(kNumTasks + 1, kNumTasks + 1); for (intptr_t i = 0; i < kNumTasks; ++i) { diff --git a/runtime/vm/thread_interrupter.h b/runtime/vm/thread_interrupter.h index cc7a71823a3..97f245b0207 100644 --- a/runtime/vm/thread_interrupter.h +++ b/runtime/vm/thread_interrupter.h @@ -37,7 +37,7 @@ class ThreadInterrupter : public AllStatic { static void InterruptThread(OSThread* thread); private: - static const intptr_t kMaxThreads = 4096; + static constexpr intptr_t kMaxThreads = 4096; static bool initialized_; static bool shutdown_; static bool thread_running_; diff --git a/runtime/vm/thread_test.cc b/runtime/vm/thread_test.cc index 582af1eaa8f..03ce0e00172 100644 --- a/runtime/vm/thread_test.cc +++ b/runtime/vm/thread_test.cc @@ -369,7 +369,7 @@ TEST_CASE(ThreadRegistry) { // A helper thread that repeatedly reads ICData class ICDataTestTask : public ThreadPool::Task { public: - static const intptr_t kTaskCount; + static constexpr intptr_t kTaskCount = 1; ICDataTestTask(Isolate* isolate, const Array& ic_datas, @@ -447,8 +447,6 @@ static Function* CreateFunction(const char* name) { return &function; } -const intptr_t ICDataTestTask::kTaskCount = 1; - // Test that checks that other threads only see a fully initialized ICData // whenever ICData is updated. ISOLATE_UNIT_TEST_CASE(ICDataTest) { @@ -511,7 +509,7 @@ ISOLATE_UNIT_TEST_CASE(ICDataTest) { // not happen in the first rendezvous, since tasks are still starting up). class SafepointTestTask : public ThreadPool::Task { public: - static const intptr_t kTaskCount; + static constexpr intptr_t kTaskCount = 5; SafepointTestTask(Isolate* isolate, Monitor* monitor, @@ -592,8 +590,6 @@ class SafepointTestTask : public ThreadPool::Task { bool local_done_; // this task has successfully safepointed >= once. }; -const intptr_t SafepointTestTask::kTaskCount = 5; - // Test rendezvous of: // - helpers in VM code, // - main thread in pure Dart, diff --git a/runtime/vm/timeline.h b/runtime/vm/timeline.h index 1cbfa1b4f2b..cc75762d3a9 100644 --- a/runtime/vm/timeline.h +++ b/runtime/vm/timeline.h @@ -681,7 +681,7 @@ class TimelineBeginEndScope : public TimelineEventScope { // A block of |TimelineEvent|s. Not thread safe. class TimelineEventBlock : public MallocAllocated { public: - static const intptr_t kBlockSize = 64; + static constexpr intptr_t kBlockSize = 64; explicit TimelineEventBlock(intptr_t index); ~TimelineEventBlock(); @@ -866,7 +866,7 @@ class TimelineEventRecorder : public MallocAllocated { friend class Timeline; private: - static const intptr_t kTrackUuidToTrackMetadataInitialCapacity = 1 << 4; + static constexpr intptr_t kTrackUuidToTrackMetadataInitialCapacity = 1 << 4; SimpleHashMap track_uuid_to_track_metadata_; Mutex track_uuid_to_track_metadata_lock_; DISALLOW_COPY_AND_ASSIGN(TimelineEventRecorder); @@ -875,7 +875,7 @@ class TimelineEventRecorder : public MallocAllocated { // An abstract recorder that stores events in a buffer of fixed capacity. class TimelineEventFixedBufferRecorder : public TimelineEventRecorder { public: - static const intptr_t kDefaultCapacity = 32 * KB; // Number of events. + static constexpr intptr_t kDefaultCapacity = 32 * KB; // Number of events. explicit TimelineEventFixedBufferRecorder(intptr_t capacity); virtual ~TimelineEventFixedBufferRecorder(); diff --git a/runtime/vm/token.h b/runtime/vm/token.h index 50cd1e72bfd..93cd314e56e 100644 --- a/runtime/vm/token.h +++ b/runtime/vm/token.h @@ -213,7 +213,7 @@ class Token { static const Kind kFirstKeyword = kABSTRACT; static const Kind kLastKeyword = kWITH; - static const int kNumKeywords = kLastKeyword - kFirstKeyword + 1; + static constexpr int kNumKeywords = kLastKeyword - kFirstKeyword + 1; static bool IsAssignmentOperator(Kind tok) { return kASSIGN <= tok && tok <= kASSIGN_COND; diff --git a/runtime/vm/unibrow.cc b/runtime/vm/unibrow.cc index c3152ab12ea..4f468ee7af0 100644 --- a/runtime/vm/unibrow.cc +++ b/runtime/vm/unibrow.cc @@ -12,9 +12,9 @@ namespace unibrow { -static const intptr_t kStartBit = (1 << 30); -static const intptr_t kChunkBits = (1 << 13); -static const int32_t kSentinel = static_cast(-1); +static constexpr intptr_t kStartBit = (1 << 30); +static constexpr intptr_t kChunkBits = (1 << 13); +static constexpr int32_t kSentinel = static_cast(-1); /** * \file @@ -46,7 +46,7 @@ static inline bool IsStart(int32_t entry) { * information available about the character. */ static bool LookupPredicate(const int32_t* table, uint16_t size, int32_t chr) { - static const intptr_t kEntryDist = 1; + const intptr_t kEntryDist = 1; uint16_t value = chr & (kChunkBits - 1); uint32_t low = 0; uint32_t high = size - 1; @@ -77,7 +77,7 @@ static bool LookupPredicate(const int32_t* table, uint16_t size, int32_t chr) { template struct MultiCharacterSpecialCase { - static const int32_t kEndOfEncoding = kSentinel; + static constexpr int32_t kEndOfEncoding = kSentinel; int32_t chars[kW]; }; @@ -100,7 +100,7 @@ static intptr_t LookupMapping(const int32_t* table, int32_t next, int32_t* result, bool* allow_caching_ptr) { - static const intptr_t kEntryDist = 2; + const intptr_t kEntryDist = 2; uint16_t key = chr & (kChunkBits - 1); uint16_t chunk_start = chr - key; uint32_t low = 0; @@ -184,8 +184,8 @@ static intptr_t LookupMapping(const int32_t* table, // Letter: point.category in ['Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl'] // clang-format off -static const uint16_t kLetterTable0Size = 431; -static const int32_t kLetterTable0[431] = { +static constexpr uint16_t kLetterTable0Size = 431; +static constexpr int32_t kLetterTable0[431] = { 1073741889, 90, 1073741921, 122, 170, 181, 186, 1073742016, // NOLINT 214, 1073742040, 246, 1073742072, @@ -294,8 +294,8 @@ static const int32_t kLetterTable0[431] = { 8140, 1073749968, 8147, 1073749974, // NOLINT 8155, 1073749984, 8172, 1073750002, 8180, 1073750006, 8188}; // NOLINT -static const uint16_t kLetterTable1Size = 87; -static const int32_t kLetterTable1[87] = { +static constexpr uint16_t kLetterTable1Size = 87; +static constexpr int32_t kLetterTable1[87] = { 113, 127, 1073741968, 156, 258, 263, 1073742090, 275, // NOLINT 277, 1073742105, 285, 292, 294, 296, 1073742122, 301, // NOLINT 1073742127, 313, 1073742140, 319, 1073742149, 329, 334, 1073742176, // NOLINT @@ -307,17 +307,17 @@ static const int32_t kLetterTable1[87] = { 4137, 1073745969, 4149, 1073745976, 4156, 1073745985, 4246, 1073746077, // NOLINT 4255, 1073746081, 4346, 1073746172, 4351, 1073746181, 4397, 1073746225, // NOLINT 4494, 1073746336, 4538, 1073746416, 4607, 1073746944, 8191 }; // NOLINT -static const uint16_t kLetterTable2Size = 4; -static const int32_t kLetterTable2[4] = { +static constexpr uint16_t kLetterTable2Size = 4; +static constexpr int32_t kLetterTable2[4] = { 1073741824, 3509, 1073745408, 8191 }; // NOLINT -static const uint16_t kLetterTable3Size = 2; -static const int32_t kLetterTable3[2] = { +static constexpr uint16_t kLetterTable3Size = 2; +static constexpr int32_t kLetterTable3[2] = { 1073741824, 8191 }; // NOLINT -static const uint16_t kLetterTable4Size = 2; -static const int32_t kLetterTable4[2] = { +static constexpr uint16_t kLetterTable4Size = 2; +static constexpr int32_t kLetterTable4[2] = { 1073741824, 8140 }; // NOLINT -static const uint16_t kLetterTable5Size = 100; -static const int32_t kLetterTable5[100] = { +static constexpr uint16_t kLetterTable5Size = 100; +static constexpr int32_t kLetterTable5[100] = { 1073741824, 1164, 1073743056, 1277, 1073743104, 1548, 1073743376, 1567, // NOLINT 1073743402, 1579, 1073743424, 1646, @@ -343,11 +343,11 @@ static const int32_t kLetterTable5[100] = { 1073744680, 2862, 1073744688, 2906, 1073744732, 2911, 1073744740, 2917, // NOLINT 1073744832, 3042, 1073744896, 8191}; // NOLINT -static const uint16_t kLetterTable6Size = 6; -static const int32_t kLetterTable6[6] = { +static constexpr uint16_t kLetterTable6Size = 6; +static constexpr int32_t kLetterTable6[6] = { 1073741824, 6051, 1073747888, 6086, 1073747915, 6139 }; // NOLINT -static const uint16_t kLetterTable7Size = 48; -static const int32_t kLetterTable7[48] = { +static constexpr uint16_t kLetterTable7Size = 48; +static constexpr int32_t kLetterTable7[48] = { 1073748224, 6765, 1073748592, 6873, 1073748736, 6918, 1073748755, 6935, // NOLINT 6941, 1073748767, 6952, 1073748778, 6966, 1073748792, 6972, 6974, // NOLINT 1073748800, 6977, 1073748803, 6980, 1073748806, 7089, 1073748947, 7485, // NOLINT @@ -388,8 +388,8 @@ bool Letter::Is(int32_t c) { static const MultiCharacterSpecialCase<1> kEcma262CanonicalizeMultiStrings0[1] = { // NOLINT {{kSentinel}} }; // NOLINT -static const uint16_t kEcma262CanonicalizeTable0Size = 498; // NOLINT -static const int32_t kEcma262CanonicalizeTable0[996] = { +static constexpr uint16_t kEcma262CanonicalizeTable0Size = 498; // NOLINT +static constexpr int32_t kEcma262CanonicalizeTable0[996] = { 1073741921, -128, 122, -128, 181, 2972, 1073742048, -128, 246, -128, 1073742072, -128, 254, -128, 255, 484, // NOLINT @@ -579,8 +579,8 @@ static const int32_t kEcma262CanonicalizeTable0[996] = { 8161, 32, 8165, 28}; // NOLINT static const MultiCharacterSpecialCase<1> kEcma262CanonicalizeMultiStrings1[1] = { // NOLINT {{kSentinel}} }; // NOLINT -static const uint16_t kEcma262CanonicalizeTable1Size = 73; // NOLINT -static const int32_t kEcma262CanonicalizeTable1[146] = { +static constexpr uint16_t kEcma262CanonicalizeTable1Size = 73; // NOLINT +static constexpr int32_t kEcma262CanonicalizeTable1[146] = { 334, -112, 1073742192, -64, 383, -64, 388, -4, 1073743056, -104, 1257, -104, 1073744944, -192, 3166, -192, // NOLINT 3169, -4, 3173, -43180, 3174, -43168, 3176, -4, 3178, -4, 3180, -4, 3187, -4, 3190, -4, // NOLINT 3201, -4, 3203, -4, 3205, -4, 3207, -4, 3209, -4, 3211, -4, 3213, -4, 3215, -4, // NOLINT @@ -593,8 +593,8 @@ static const int32_t kEcma262CanonicalizeTable1[146] = { 3373, -29056 }; // NOLINT static const MultiCharacterSpecialCase<1> kEcma262CanonicalizeMultiStrings5[1] = { // NOLINT {{kSentinel}} }; // NOLINT -static const uint16_t kEcma262CanonicalizeTable5Size = 95; // NOLINT -static const int32_t kEcma262CanonicalizeTable5 +static constexpr uint16_t kEcma262CanonicalizeTable5Size = 95; // NOLINT +static constexpr int32_t kEcma262CanonicalizeTable5 [190] = {1601, -4, 1603, -4, 1605, -4, 1607, -4, 1609, -4, 1611, -4, 1613, -4, 1615, -4, // NOLINT 1617, -4, 1619, -4, 1621, -4, 1623, -4, @@ -621,8 +621,8 @@ static const int32_t kEcma262CanonicalizeTable5 1957, -4, 1959, -4, 1961, -4}; // NOLINT static const MultiCharacterSpecialCase<1> kEcma262CanonicalizeMultiStrings7[1] = { // NOLINT {{kSentinel}} }; // NOLINT -static const uint16_t kEcma262CanonicalizeTable7Size = 2; // NOLINT -static const int32_t kEcma262CanonicalizeTable7[4] = { +static constexpr uint16_t kEcma262CanonicalizeTable7Size = 2; // NOLINT +static constexpr int32_t kEcma262CanonicalizeTable7[4] = { 1073749825, -128, 8026, -128 }; // NOLINT intptr_t Ecma262Canonicalize::Convert(int32_t c, int32_t n, @@ -1171,8 +1171,8 @@ static const MultiCharacterSpecialCase<4> {{8161, 8169, kSentinel}}, {{8165, 8172, kSentinel}}, {{kSentinel}}}; // NOLINT -static const uint16_t kEcma262UnCanonicalizeTable0Size = 1005; // NOLINT -static const int32_t kEcma262UnCanonicalizeTable0[2010] = { +static constexpr uint16_t kEcma262UnCanonicalizeTable0Size = 1005; // NOLINT +static constexpr int32_t kEcma262UnCanonicalizeTable0[2010] = { 1073741889, 1, 90, 5, 1073741921, 1, 122, 5, 181, 9, 1073742016, 13, 214, 17, 1073742040, 21, // NOLINT @@ -1572,8 +1572,8 @@ static const MultiCharacterSpecialCase<2> kEcma262UnCanonicalizeMultiStrings1[83 {{11486, 11487}}, {{11488, 11489}}, {{11490, 11491}}, {{11499, 11500}}, // NOLINT {{11501, 11502}}, {{11506, 11507}}, {{4256, 11520}}, {{4293, 11557}}, // NOLINT {{4295, 11559}}, {{4301, 11565}}, {{kSentinel}} }; // NOLINT -static const uint16_t kEcma262UnCanonicalizeTable1Size = 149; // NOLINT -static const int32_t kEcma262UnCanonicalizeTable1[298] = { +static constexpr uint16_t kEcma262UnCanonicalizeTable1Size = 149; // NOLINT +static constexpr int32_t kEcma262UnCanonicalizeTable1[298] = { 306, 1, 334, 1, 1073742176, 5, 367, 9, 1073742192, 5, 383, 9, 387, 13, 388, 13, // NOLINT 1073743030, 17, 1231, 21, 1073743056, 17, 1257, 21, 1073744896, 25, 3118, 29, 1073744944, 25, 3166, 29, // NOLINT 3168, 33, 3169, 33, 3170, 37, 3171, 41, 3172, 45, 3173, 49, 3174, 53, 3175, 57, // NOLINT @@ -1699,8 +1699,8 @@ static const MultiCharacterSpecialCase<2> {{670, 42928}}, {{647, 42929}}, {{kSentinel}}}; // NOLINT -static const uint16_t kEcma262UnCanonicalizeTable5Size = 198; // NOLINT -static const int32_t kEcma262UnCanonicalizeTable5 +static constexpr uint16_t kEcma262UnCanonicalizeTable5Size = 198; // NOLINT +static constexpr int32_t kEcma262UnCanonicalizeTable5 [396] = {1600, 1, 1601, 1, 1602, 5, 1603, 5, 1604, 9, 1605, 9, 1606, 13, 1607, 13, // NOLINT 1608, 17, 1609, 17, 1610, 21, 1611, 21, @@ -1753,8 +1753,8 @@ static const int32_t kEcma262UnCanonicalizeTable5 1968, 405, 1969, 409}; // NOLINT static const MultiCharacterSpecialCase<2> kEcma262UnCanonicalizeMultiStrings7[3] = { // NOLINT {{65313, 65345}}, {{65338, 65370}}, {{kSentinel}} }; // NOLINT -static const uint16_t kEcma262UnCanonicalizeTable7Size = 4; // NOLINT -static const int32_t kEcma262UnCanonicalizeTable7[8] = { +static constexpr uint16_t kEcma262UnCanonicalizeTable7Size = 4; // NOLINT +static constexpr int32_t kEcma262UnCanonicalizeTable7[8] = { 1073749793, 1, 7994, 5, 1073749825, 1, 8026, 5 }; // NOLINT intptr_t Ecma262UnCanonicalize::Convert(int32_t c, int32_t n, @@ -1796,8 +1796,8 @@ intptr_t Ecma262UnCanonicalize::Convert(int32_t c, static const MultiCharacterSpecialCase<1> kCanonicalizationRangeMultiStrings0[1] = { // NOLINT {{kSentinel}} }; // NOLINT -static const uint16_t kCanonicalizationRangeTable0Size = 70; // NOLINT -static const int32_t kCanonicalizationRangeTable0[140] = { +static constexpr uint16_t kCanonicalizationRangeTable0Size = 70; // NOLINT +static constexpr int32_t kCanonicalizationRangeTable0[140] = { 1073741889, 100, 90, 0, 1073741921, 100, 122, 0, 1073742016, 88, 214, 0, 1073742040, 24, 222, 0, // NOLINT 1073742048, 88, 246, 0, 1073742072, 24, 254, 0, 1073742715, 8, 893, 0, 1073742728, 8, 906, 0, // NOLINT 1073742749, 8, 927, 0, 1073742759, 16, 939, 0, 1073742765, 8, 943, 0, 1073742781, 8, 959, 0, // NOLINT @@ -1809,14 +1809,14 @@ static const int32_t kCanonicalizationRangeTable0[140] = { 1073749864, 28, 8047, 0, 1073749874, 12, 8053, 0, 1073749960, 12, 8139, 0 }; // NOLINT static const MultiCharacterSpecialCase<1> kCanonicalizationRangeMultiStrings1[1] = { // NOLINT {{kSentinel}} }; // NOLINT -static const uint16_t kCanonicalizationRangeTable1Size = 14; // NOLINT -static const int32_t kCanonicalizationRangeTable1[28] = { +static constexpr uint16_t kCanonicalizationRangeTable1Size = 14; // NOLINT +static constexpr int32_t kCanonicalizationRangeTable1[28] = { 1073742176, 60, 367, 0, 1073742192, 60, 383, 0, 1073743030, 100, 1231, 0, 1073743056, 100, 1257, 0, // NOLINT 1073744896, 184, 3118, 0, 1073744944, 184, 3166, 0, 1073745152, 148, 3365, 0 }; // NOLINT static const MultiCharacterSpecialCase<1> kCanonicalizationRangeMultiStrings7[1] = { // NOLINT {{kSentinel}} }; // NOLINT -static const uint16_t kCanonicalizationRangeTable7Size = 4; // NOLINT -static const int32_t kCanonicalizationRangeTable7[8] = { +static constexpr uint16_t kCanonicalizationRangeTable7Size = 4; // NOLINT +static constexpr int32_t kCanonicalizationRangeTable7[8] = { 1073749793, 100, 7994, 0, 1073749825, 100, 8026, 0 }; // NOLINT // clang-format on diff --git a/runtime/vm/unibrow.h b/runtime/vm/unibrow.h index 565a9a871cf..c01c2aa83f8 100644 --- a/runtime/vm/unibrow.h +++ b/runtime/vm/unibrow.h @@ -35,10 +35,10 @@ class Mapping { : code_point_(code_point), offset_(offset) {} int32_t code_point_; signed offset_; - static const intptr_t kNoChar = (1 << 21) - 1; + static constexpr intptr_t kNoChar = (1 << 21) - 1; }; - static const intptr_t kSize = size; - static const intptr_t kMask = kSize - 1; + static constexpr intptr_t kSize = size; + static constexpr intptr_t kMask = kSize - 1; CacheEntry entries_[kSize]; }; @@ -46,21 +46,21 @@ struct Letter { static bool Is(int32_t c); }; struct Ecma262Canonicalize { - static const intptr_t kMaxWidth = 1; + static constexpr intptr_t kMaxWidth = 1; static intptr_t Convert(int32_t c, int32_t n, int32_t* result, bool* allow_caching_ptr); }; struct Ecma262UnCanonicalize { - static const intptr_t kMaxWidth = 4; + static constexpr intptr_t kMaxWidth = 4; static intptr_t Convert(int32_t c, int32_t n, int32_t* result, bool* allow_caching_ptr); }; struct CanonicalizationRange { - static const intptr_t kMaxWidth = 1; + static constexpr intptr_t kMaxWidth = 1; static intptr_t Convert(int32_t c, int32_t n, int32_t* result, diff --git a/runtime/vm/unicode.cc b/runtime/vm/unicode.cc index fc2a8bfc308..21d1800b124 100644 --- a/runtime/vm/unicode.cc +++ b/runtime/vm/unicode.cc @@ -13,9 +13,9 @@ namespace dart { // A constant mask that can be 'and'ed with a word of data to determine if it // is all ASCII (with no Latin1 characters). #if defined(ARCH_IS_64_BIT) -static const uintptr_t kAsciiWordMask = DART_UINT64_C(0x8080808080808080); +static constexpr uintptr_t kAsciiWordMask = DART_UINT64_C(0x8080808080808080); #else -static const uintptr_t kAsciiWordMask = 0x80808080u; +static constexpr uintptr_t kAsciiWordMask = 0x80808080u; #endif intptr_t Utf8::Length(const String& str) { diff --git a/runtime/vm/unicode_test.cc b/runtime/vm/unicode_test.cc index 700ce5317e3..7273d832e87 100644 --- a/runtime/vm/unicode_test.cc +++ b/runtime/vm/unicode_test.cc @@ -12,7 +12,7 @@ ISOLATE_UNIT_TEST_CASE(Utf8Encode) { const intptr_t kInputLen = 3; const uint16_t kInput[kInputLen] = {0xe6, 0xe7, 0xe8}; // æøå const String& input = String::Handle(String::FromUTF16(kInput, kInputLen)); - static const uintptr_t kBufferLength = 10; + const uintptr_t kBufferLength = 10; unsigned char buffer[kBufferLength]; for (uintptr_t i = 0; i < kBufferLength; i++) { buffer[i] = 42; diff --git a/runtime/vm/unit_test.h b/runtime/vm/unit_test.h index c7d5429ea50..fe51c435fc7 100644 --- a/runtime/vm/unit_test.h +++ b/runtime/vm/unit_test.h @@ -488,22 +488,22 @@ void SetupCoreLibrariesForUnitTest(); template struct is_void { - static const bool value = false; + static constexpr bool value = false; }; template <> struct is_void { - static const bool value = true; + static constexpr bool value = true; }; template struct is_double { - static const bool value = false; + static constexpr bool value = false; }; template <> struct is_double { - static const bool value = true; + static constexpr bool value = true; }; class AssemblerTest { @@ -634,7 +634,7 @@ class AssemblerTest { const char* name_; compiler::Assembler* assembler_; Code& code_; - static const intptr_t DISASSEMBLY_SIZE = 10240; + static constexpr intptr_t DISASSEMBLY_SIZE = 10240; char* disassembly_; DISALLOW_COPY_AND_ASSIGN(AssemblerTest); diff --git a/runtime/vm/utils_test.cc b/runtime/vm/utils_test.cc index 8cc9cb8b7bc..0b7bc837f6c 100644 --- a/runtime/vm/utils_test.cc +++ b/runtime/vm/utils_test.cc @@ -246,7 +246,7 @@ VM_UNIT_TEST_CASE(CountZerosWord) { EXPECT_EQ(kBitsPerWord - 3, Utils::CountLeadingZerosWord(0x4)); EXPECT_EQ(0, Utils::CountTrailingZerosWord(kUwordMax)); EXPECT_EQ(0, Utils::CountLeadingZerosWord(kUwordMax)); - static const uword kTopBit = static_cast(1) << (kBitsPerWord - 1); + const uword kTopBit = static_cast(1) << (kBitsPerWord - 1); EXPECT_EQ(kBitsPerWord - 1, Utils::CountTrailingZerosWord(kTopBit)); EXPECT_EQ(0, Utils::CountLeadingZerosWord(kTopBit)); } diff --git a/runtime/vm/zone.h b/runtime/vm/zone.h index d8f12477b3b..ba18349cd3c 100644 --- a/runtime/vm/zone.h +++ b/runtime/vm/zone.h @@ -85,7 +85,7 @@ class Zone { } // All pointers returned from AllocateUnsafe() and New() have this alignment. - static const intptr_t kAlignment = kDoubleSize; + static constexpr intptr_t kAlignment = kDoubleSize; static void Init(); static void Cleanup(); @@ -98,16 +98,16 @@ class Zone { ~Zone(); // Delete all memory associated with the zone. // Default initial chunk size. - static const intptr_t kInitialChunkSize = 128; + static constexpr intptr_t kInitialChunkSize = 128; // Default segment size. - static const intptr_t kSegmentSize = 64 * KB; + static constexpr intptr_t kSegmentSize = 64 * KB; // Zap value used to indicate deleted zone area (debug purposes). - static const unsigned char kZapDeletedByte = 0x42; + static constexpr unsigned char kZapDeletedByte = 0x42; // Zap value used to indicate uninitialized zone area (debug purposes). - static const unsigned char kZapUninitializedByte = 0xab; + static constexpr unsigned char kZapUninitializedByte = 0xab; // Total size of current zone segments. static RelaxedAtomic total_size_; diff --git a/runtime/vm/zone_test.cc b/runtime/vm/zone_test.cc index 9dec6b461b2..511739884ea 100644 --- a/runtime/vm/zone_test.cc +++ b/runtime/vm/zone_test.cc @@ -189,7 +189,7 @@ TEST_CASE(PrintToString) { #if !defined(PRODUCT) // Allow for pooling in the malloc implementation. -static const int64_t kRssSlack = 20 * MB; +static constexpr int64_t kRssSlack = 20 * MB; #endif // !defined(PRODUCT) // clang-format off