Revision: 17955
Author: [email protected]
Date: Thu Nov 21 09:55:15 2013 UTC
Log: Implement Math.random() purely in JavaScript.
This removes tons of architecture-specific code and makes it easy to
experiment with other pseudo-RNG algorithms. The crankshafted code is
extremely good, keeping all things unboxed and doing only minimal
checks, so it is basically equivalent to the handwritten code.
When benchmarks are run without parallel recompilation, we get a few
percent regression on SunSpider's string-validate-input and
string-base64, but these benchmarks run so fast that the overall
SunSpider score is hardly affected and within the usual jitter. Note
that these benchmarks actually run even faster when we don't
crankshaft at all on the main thread (the regression is not caused by
bad code, it is caused by Crankshaft needing a few hundred microsecond
for compilation of a trivial function). Luckily, when parallel
recompilation is enabled, i.e. in the browser, we see no regression at
all!
[email protected]
Review URL: https://codereview.chromium.org/68723002
http://code.google.com/p/v8/source/detail?r=17955
Modified:
/branches/bleeding_edge/src/arm/full-codegen-arm.cc
/branches/bleeding_edge/src/arm/lithium-arm.cc
/branches/bleeding_edge/src/arm/lithium-arm.h
/branches/bleeding_edge/src/arm/lithium-codegen-arm.cc
/branches/bleeding_edge/src/assembler.cc
/branches/bleeding_edge/src/assembler.h
/branches/bleeding_edge/src/bootstrapper.cc
/branches/bleeding_edge/src/contexts.h
/branches/bleeding_edge/src/globals.h
/branches/bleeding_edge/src/heap.cc
/branches/bleeding_edge/src/hydrogen-instructions.h
/branches/bleeding_edge/src/hydrogen.cc
/branches/bleeding_edge/src/ia32/full-codegen-ia32.cc
/branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc
/branches/bleeding_edge/src/ia32/lithium-ia32.cc
/branches/bleeding_edge/src/ia32/lithium-ia32.h
/branches/bleeding_edge/src/math.js
/branches/bleeding_edge/src/mips/full-codegen-mips.cc
/branches/bleeding_edge/src/mips/lithium-codegen-mips.cc
/branches/bleeding_edge/src/mips/lithium-mips.cc
/branches/bleeding_edge/src/mips/lithium-mips.h
/branches/bleeding_edge/src/objects.h
/branches/bleeding_edge/src/runtime.h
/branches/bleeding_edge/src/serialize.cc
/branches/bleeding_edge/src/v8.cc
/branches/bleeding_edge/src/v8.h
/branches/bleeding_edge/src/x64/full-codegen-x64.cc
/branches/bleeding_edge/src/x64/lithium-codegen-x64.cc
/branches/bleeding_edge/src/x64/lithium-x64.cc
/branches/bleeding_edge/src/x64/lithium-x64.h
/branches/bleeding_edge/test/cctest/test-weaktypedarrays.cc
=======================================
--- /branches/bleeding_edge/src/arm/full-codegen-arm.cc Wed Nov 20 14:17:47
2013 UTC
+++ /branches/bleeding_edge/src/arm/full-codegen-arm.cc Thu Nov 21 09:55:15
2013 UTC
@@ -3345,50 +3345,6 @@
__ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
context()->Plug(r0);
}
-
-
-void FullCodeGenerator::EmitRandomHeapNumber(CallRuntime* expr) {
- ASSERT(expr->arguments()->length() == 0);
- Label slow_allocate_heapnumber;
- Label heapnumber_allocated;
-
- __ LoadRoot(r6, Heap::kHeapNumberMapRootIndex);
- __ AllocateHeapNumber(r4, r1, r2, r6, &slow_allocate_heapnumber);
- __ jmp(&heapnumber_allocated);
-
- __ bind(&slow_allocate_heapnumber);
- // Allocate a heap number.
- __ CallRuntime(Runtime::kNumberAlloc, 0);
- __ mov(r4, Operand(r0));
-
- __ bind(&heapnumber_allocated);
-
- // Convert 32 random bits in r0 to 0.(32 random bits) in a double
- // by computing:
- // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
- __ PrepareCallCFunction(1, r0);
- __ ldr(r0,
- ContextOperand(context_register(), Context::GLOBAL_OBJECT_INDEX));
- __ ldr(r0, FieldMemOperand(r0, GlobalObject::kNativeContextOffset));
- __ CallCFunction(ExternalReference::random_uint32_function(isolate()),
1);
-
- // 0x41300000 is the top half of 1.0 x 2^20 as a double.
- // Create this constant using mov/orr to avoid PC relative load.
- __ mov(r1, Operand(0x41000000));
- __ orr(r1, r1, Operand(0x300000));
- // Move 0x41300000xxxxxxxx (x = random bits) to VFP.
- __ vmov(d7, r0, r1);
- // Move 0x4130000000000000 to VFP.
- __ mov(r0, Operand::Zero());
- __ vmov(d8, r0, r1);
- // Subtract and store the result in the heap number.
- __ vsub(d7, d7, d8);
- __ sub(r0, r4, Operand(kHeapObjectTag));
- __ vstr(d7, r0, HeapNumber::kValueOffset);
- __ mov(r0, r4);
-
- context()->Plug(r0);
-}
void FullCodeGenerator::EmitSubString(CallRuntime* expr) {
=======================================
--- /branches/bleeding_edge/src/arm/lithium-arm.cc Wed Nov 20 13:28:19 2013
UTC
+++ /branches/bleeding_edge/src/arm/lithium-arm.cc Thu Nov 21 09:55:15 2013
UTC
@@ -1718,19 +1718,6 @@
instr,
CAN_DEOPTIMIZE_EAGERLY);
}
-
-
-LInstruction* LChunkBuilder::DoRandom(HRandom* instr) {
- ASSERT(instr->representation().IsDouble());
- ASSERT(instr->global_object()->representation().IsTagged());
- LOperand* global_object = UseTempRegister(instr->global_object());
- LOperand* scratch = TempRegister();
- LOperand* scratch2 = TempRegister();
- LOperand* scratch3 = TempRegister();
- LRandom* result = new(zone()) LRandom(
- global_object, scratch, scratch2, scratch3);
- return DefineFixedDouble(result, d7);
-}
LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
=======================================
--- /branches/bleeding_edge/src/arm/lithium-arm.h Tue Nov 19 16:41:07 2013
UTC
+++ /branches/bleeding_edge/src/arm/lithium-arm.h Thu Nov 21 09:55:15 2013
UTC
@@ -155,7 +155,6 @@
V(Parameter) \
V(Power) \
V(PushArgument) \
- V(Random) \
V(RegExpLiteral) \
V(Return) \
V(SeqStringGetChar) \
@@ -1481,28 +1480,6 @@
};
-class LRandom V8_FINAL : public LTemplateInstruction<1, 1, 3> {
- public:
- LRandom(LOperand* global_object,
- LOperand* scratch,
- LOperand* scratch2,
- LOperand* scratch3) {
- inputs_[0] = global_object;
- temps_[0] = scratch;
- temps_[1] = scratch2;
- temps_[2] = scratch3;
- }
-
- LOperand* global_object() const { return inputs_[0]; }
- LOperand* scratch() const { return temps_[0]; }
- LOperand* scratch2() const { return temps_[1]; }
- LOperand* scratch3() const { return temps_[2]; }
-
- DECLARE_CONCRETE_INSTRUCTION(Random, "random")
- DECLARE_HYDROGEN_ACCESSOR(Random)
-};
-
-
class LArithmeticD V8_FINAL : public LTemplateInstruction<1, 2, 0> {
public:
LArithmeticD(Token::Value op, LOperand* left, LOperand* right)
=======================================
--- /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Wed Nov 20
13:44:24 2013 UTC
+++ /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Thu Nov 21
09:55:15 2013 UTC
@@ -3932,68 +3932,6 @@
__ CallStub(&stub);
}
}
-
-
-void LCodeGen::DoRandom(LRandom* instr) {
- // Assert that the register size is indeed the size of each seed.
- static const int kSeedSize = sizeof(uint32_t);
- STATIC_ASSERT(kPointerSize == kSeedSize);
-
- // Load native context
- Register global_object = ToRegister(instr->global_object());
- Register native_context = global_object;
- __ ldr(native_context, FieldMemOperand(
- global_object, GlobalObject::kNativeContextOffset));
-
- // Load state (FixedArray of the native context's random seeds)
- static const int kRandomSeedOffset =
- FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize;
- Register state = native_context;
- __ ldr(state, FieldMemOperand(native_context, kRandomSeedOffset));
-
- // Load state[0].
- Register state0 = ToRegister(instr->scratch());
- __ ldr(state0, FieldMemOperand(state, ByteArray::kHeaderSize));
- // Load state[1].
- Register state1 = ToRegister(instr->scratch2());
- __ ldr(state1, FieldMemOperand(state, ByteArray::kHeaderSize +
kSeedSize));
-
- // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16)
- Register scratch3 = ToRegister(instr->scratch3());
- Register scratch4 = scratch0();
- __ and_(scratch3, state0, Operand(0xFFFF));
- __ mov(scratch4, Operand(18273));
- __ mul(scratch3, scratch3, scratch4);
- __ add(state0, scratch3, Operand(state0, LSR, 16));
- // Save state[0].
- __ str(state0, FieldMemOperand(state, ByteArray::kHeaderSize));
-
- // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16)
- __ and_(scratch3, state1, Operand(0xFFFF));
- __ mov(scratch4, Operand(36969));
- __ mul(scratch3, scratch3, scratch4);
- __ add(state1, scratch3, Operand(state1, LSR, 16));
- // Save state[1].
- __ str(state1, FieldMemOperand(state, ByteArray::kHeaderSize +
kSeedSize));
-
- // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF)
- Register random = scratch4;
- __ and_(random, state1, Operand(0x3FFFF));
- __ add(random, random, Operand(state0, LSL, 14));
-
- // 0x41300000 is the top half of 1.0 x 2^20 as a double.
- // Create this constant using mov/orr to avoid PC relative load.
- __ mov(scratch3, Operand(0x41000000));
- __ orr(scratch3, scratch3, Operand(0x300000));
- // Move 0x41300000xxxxxxxx (x = random bits) to VFP.
- DwVfpRegister result = ToDoubleRegister(instr->result());
- __ vmov(result, random, scratch3);
- // Move 0x4130000000000000 to VFP.
- __ mov(scratch4, Operand::Zero());
- DwVfpRegister scratch5 = double_scratch0();
- __ vmov(scratch5, scratch4, scratch3);
- __ vsub(result, result, scratch5);
-}
void LCodeGen::DoMathExp(LMathExp* instr) {
=======================================
--- /branches/bleeding_edge/src/assembler.cc Mon Nov 11 18:00:52 2013 UTC
+++ /branches/bleeding_edge/src/assembler.cc Thu Nov 21 09:55:15 2013 UTC
@@ -1059,12 +1059,6 @@
isolate,
FUNCTION_ADDR(HandleScope::DeleteExtensions)));
}
-
-
-ExternalReference ExternalReference::random_uint32_function(
- Isolate* isolate) {
- return ExternalReference(Redirect(isolate, FUNCTION_ADDR(V8::Random)));
-}
ExternalReference ExternalReference::get_date_field_function(
=======================================
--- /branches/bleeding_edge/src/assembler.h Fri Nov 15 12:24:10 2013 UTC
+++ /branches/bleeding_edge/src/assembler.h Thu Nov 21 09:55:15 2013 UTC
@@ -718,7 +718,6 @@
Isolate* isolate);
static ExternalReference flush_icache_function(Isolate* isolate);
static ExternalReference perform_gc_function(Isolate* isolate);
- static ExternalReference random_uint32_function(Isolate* isolate);
static ExternalReference transcendental_cache_array_address(Isolate*
isolate);
static ExternalReference delete_handle_scope_extensions(Isolate*
isolate);
=======================================
--- /branches/bleeding_edge/src/bootstrapper.cc Tue Nov 19 13:38:15 2013 UTC
+++ /branches/bleeding_edge/src/bootstrapper.cc Thu Nov 21 09:55:15 2013 UTC
@@ -1308,10 +1308,6 @@
// Initialize the embedder data slot.
Handle<FixedArray> embedder_data = factory->NewFixedArray(2);
native_context()->set_embedder_data(*embedder_data);
-
- // Allocate the random seed slot.
- Handle<ByteArray> random_seed = factory->NewByteArray(kRandomStateSize);
- native_context()->set_random_seed(*random_seed);
}
@@ -2635,13 +2631,36 @@
InitializeExperimentalGlobal();
if (!InstallExperimentalNatives()) return;
- // Initially seed the per-context random number generator
- // using the per-isolate random number generator.
- uint32_t* state = reinterpret_cast<uint32_t*>(
- native_context()->random_seed()->GetDataStartAddress());
- do {
- isolate->random_number_generator()->NextBytes(state, kRandomStateSize);
- } while (state[0] == 0 || state[1] == 0);
+ // We can't (de-)serialize typed arrays currently, but we are lucky: The
state
+ // of the random number generator needs no initialization during snapshot
+ // creation time.
+ if (!Serializer::enabled()) {
+ // Initially seed the per-context random number generator using the
+ // per-isolate random number generator.
+ const int num_elems = 2;
+ uint32_t* state = new uint32_t[num_elems];
+ const int num_bytes = num_elems * sizeof(*state);
+ // We have to delete the state when the context dies, so we remember
it in
+ // the context (encoded as a Smi, our usual technique for aligned
pointers)
+ // and do the cleanup in
WeakListVisitor<Context>::VisitPhantomObject().
+ // This hack can go away when we have a way to allocate the backing
store of
+ // typed arrays on the heap.
+ native_context()->set_random_state(reinterpret_cast<Smi*>(state));
+ ASSERT(native_context()->random_state()->IsSmi());
+
+ do {
+ isolate->random_number_generator()->NextBytes(state, num_bytes);
+ } while (state[0] == 0 || state[1] == 0);
+
+ v8::Local<v8::ArrayBuffer> buffer = v8::ArrayBuffer::New(state,
num_bytes);
+ v8::Local<v8::Uint32Array> ta = v8::Uint32Array::New(buffer, 0,
num_elems);
+ Handle<JSBuiltinsObject> builtins(native_context()->builtins());
+ ForceSetProperty(builtins,
+ factory()->InternalizeOneByteString(
+ STATIC_ASCII_VECTOR("rngstate")),
+ Utils::OpenHandle(*ta),
+ NONE);
+ }
result_ = native_context();
}
=======================================
--- /branches/bleeding_edge/src/contexts.h Wed Sep 4 13:53:24 2013 UTC
+++ /branches/bleeding_edge/src/contexts.h Thu Nov 21 09:55:15 2013 UTC
@@ -185,7 +185,7 @@
V(GENERATOR_OBJECT_PROTOTYPE_MAP_INDEX, Map, \
generator_object_prototype_map) \
V(GENERATOR_RESULT_MAP_INDEX, Map, generator_result_map) \
- V(RANDOM_SEED_INDEX, ByteArray, random_seed)
+ V(RANDOM_STATE_INDEX, Smi, random_state)
// JSFunctions are pairs (context, function code), sometimes also called
// closures. A Context object is used to represent function contexts and
@@ -332,7 +332,7 @@
STRICT_MODE_GENERATOR_FUNCTION_MAP_INDEX,
GENERATOR_OBJECT_PROTOTYPE_MAP_INDEX,
GENERATOR_RESULT_MAP_INDEX,
- RANDOM_SEED_INDEX,
+ RANDOM_STATE_INDEX,
// Properties from here are treated as weak references by the full GC.
// Scavenge treats them as strong references.
=======================================
--- /branches/bleeding_edge/src/globals.h Fri Nov 8 17:35:58 2013 UTC
+++ /branches/bleeding_edge/src/globals.h Thu Nov 21 09:55:15 2013 UTC
@@ -251,9 +251,6 @@
const int kDoubleSizeLog2 = 3;
-// Size of the state of a the random number generator.
-const int kRandomStateSize = 2 * kIntSize;
-
#if V8_HOST_ARCH_64_BIT
const int kPointerSizeLog2 = 3;
const intptr_t kIntptrSignBit = V8_INT64_C(0x8000000000000000);
=======================================
--- /branches/bleeding_edge/src/heap.cc Thu Nov 21 08:06:02 2013 UTC
+++ /branches/bleeding_edge/src/heap.cc Thu Nov 21 09:55:15 2013 UTC
@@ -1765,7 +1765,9 @@
}
}
- static void VisitPhantomObject(Heap*, Context*) {
+ static void VisitPhantomObject(Heap*, Context* context) {
+ // A bit of a hack, see the comment at the end of Genesis::Genesis().
+ delete[] reinterpret_cast<uint32_t*>(context->random_state());
}
static int WeakNextOffset() {
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.h Wed Nov 20 12:43:33
2013 UTC
+++ /branches/bleeding_edge/src/hydrogen-instructions.h Thu Nov 21 09:55:15
2013 UTC
@@ -155,7 +155,6 @@
V(Parameter) \
V(Power) \
V(PushArgument) \
- V(Random) \
V(RegExpLiteral) \
V(Return) \
V(Ror) \
@@ -4724,28 +4723,6 @@
};
-class HRandom V8_FINAL : public HTemplateInstruction<1> {
- public:
- DECLARE_INSTRUCTION_FACTORY_P1(HRandom, HValue*);
-
- HValue* global_object() { return OperandAt(0); }
-
- virtual Representation RequiredInputRepresentation(int index)
V8_OVERRIDE {
- return Representation::Tagged();
- }
-
- DECLARE_CONCRETE_INSTRUCTION(Random)
-
- private:
- explicit HRandom(HValue* global_object) {
- SetOperandAt(0, global_object);
- set_representation(Representation::Double());
- }
-
- virtual bool IsDeletable() const V8_OVERRIDE { return true; }
-};
-
-
class HAdd V8_FINAL : public HArithmeticBinaryOperation {
public:
static HInstruction* New(Zone* zone,
=======================================
--- /branches/bleeding_edge/src/hydrogen.cc Wed Nov 20 12:43:33 2013 UTC
+++ /branches/bleeding_edge/src/hydrogen.cc Thu Nov 21 09:55:15 2013 UTC
@@ -7488,16 +7488,6 @@
ast_context()->ReturnInstruction(result, expr->id());
return true;
}
- break;
- case kMathRandom:
- if (argument_count == 1 && check_type == RECEIVER_MAP_CHECK) {
- AddCheckConstantFunction(expr->holder(), receiver, receiver_map);
- Drop(1); // Receiver.
- HGlobalObject* global_object = Add<HGlobalObject>();
- HRandom* result = New<HRandom>(global_object);
- ast_context()->ReturnInstruction(result, expr->id());
- return true;
- }
break;
case kMathMax:
case kMathMin:
@@ -9871,14 +9861,6 @@
// %_Log is ignored in optimized code.
return ast_context()->ReturnValue(graph()->GetConstantUndefined());
}
-
-
-// Fast support for Math.random().
-void HOptimizedGraphBuilder::GenerateRandomHeapNumber(CallRuntime* call) {
- HGlobalObject* global_object = Add<HGlobalObject>();
- HRandom* result = New<HRandom>(global_object);
- return ast_context()->ReturnInstruction(result, call->id());
-}
// Fast support for StringAdd.
=======================================
--- /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Wed Nov 20
14:17:47 2013 UTC
+++ /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Thu Nov 21
09:55:15 2013 UTC
@@ -3294,57 +3294,6 @@
__ mov(eax, isolate()->factory()->undefined_value());
context()->Plug(eax);
}
-
-
-void FullCodeGenerator::EmitRandomHeapNumber(CallRuntime* expr) {
- ASSERT(expr->arguments()->length() == 0);
-
- Label slow_allocate_heapnumber;
- Label heapnumber_allocated;
-
- __ AllocateHeapNumber(edi, ebx, ecx, &slow_allocate_heapnumber);
- __ jmp(&heapnumber_allocated);
-
- __ bind(&slow_allocate_heapnumber);
- // Allocate a heap number.
- __ CallRuntime(Runtime::kNumberAlloc, 0);
- __ mov(edi, eax);
-
- __ bind(&heapnumber_allocated);
-
- __ PrepareCallCFunction(1, ebx);
- __ mov(eax, ContextOperand(context_register(),
Context::GLOBAL_OBJECT_INDEX));
- __ mov(eax, FieldOperand(eax, GlobalObject::kNativeContextOffset));
- __ mov(Operand(esp, 0), eax);
- __ CallCFunction(ExternalReference::random_uint32_function(isolate()),
1);
-
- // Convert 32 random bits in eax to 0.(32 random bits) in a double
- // by computing:
- // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
- // This is implemented on both SSE2 and FPU.
- if (CpuFeatures::IsSupported(SSE2)) {
- CpuFeatureScope fscope(masm(), SSE2);
- __ mov(ebx, Immediate(0x49800000)); // 1.0 x 2^20 as single.
- __ movd(xmm1, ebx);
- __ movd(xmm0, eax);
- __ cvtss2sd(xmm1, xmm1);
- __ xorps(xmm0, xmm1);
- __ subsd(xmm0, xmm1);
- __ movsd(FieldOperand(edi, HeapNumber::kValueOffset), xmm0);
- } else {
- // 0x4130000000000000 is 1.0 x 2^20 as a double.
- __ mov(FieldOperand(edi, HeapNumber::kExponentOffset),
- Immediate(0x41300000));
- __ mov(FieldOperand(edi, HeapNumber::kMantissaOffset), eax);
- __ fld_d(FieldOperand(edi, HeapNumber::kValueOffset));
- __ mov(FieldOperand(edi, HeapNumber::kMantissaOffset), Immediate(0));
- __ fld_d(FieldOperand(edi, HeapNumber::kValueOffset));
- __ fsubp(1);
- __ fstp_d(FieldOperand(edi, HeapNumber::kValueOffset));
- }
- __ mov(eax, edi);
- context()->Plug(eax);
-}
void FullCodeGenerator::EmitSubString(CallRuntime* expr) {
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Wed Nov 20
12:43:33 2013 UTC
+++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Thu Nov 21
09:55:15 2013 UTC
@@ -4165,69 +4165,6 @@
__ CallStub(&stub);
}
}
-
-
-void LCodeGen::DoRandom(LRandom* instr) {
- CpuFeatureScope scope(masm(), SSE2);
-
- // Assert that the register size is indeed the size of each seed.
- static const int kSeedSize = sizeof(uint32_t);
- STATIC_ASSERT(kPointerSize == kSeedSize);
-
- // Load native context
- Register global_object = ToRegister(instr->global_object());
- Register native_context = global_object;
- __ mov(native_context, FieldOperand(
- global_object, GlobalObject::kNativeContextOffset));
-
- // Load state (FixedArray of the native context's random seeds)
- static const int kRandomSeedOffset =
- FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize;
- Register state = native_context;
- __ mov(state, FieldOperand(native_context, kRandomSeedOffset));
-
- // Load state[0].
- Register state0 = ToRegister(instr->scratch());
- __ mov(state0, FieldOperand(state, ByteArray::kHeaderSize));
- // Load state[1].
- Register state1 = ToRegister(instr->scratch2());
- __ mov(state1, FieldOperand(state, ByteArray::kHeaderSize + kSeedSize));
-
- // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16)
- Register scratch3 = ToRegister(instr->scratch3());
- __ movzx_w(scratch3, state0);
- __ imul(scratch3, scratch3, 18273);
- __ shr(state0, 16);
- __ add(state0, scratch3);
- // Save state[0].
- __ mov(FieldOperand(state, ByteArray::kHeaderSize), state0);
-
- // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16)
- __ movzx_w(scratch3, state1);
- __ imul(scratch3, scratch3, 36969);
- __ shr(state1, 16);
- __ add(state1, scratch3);
- // Save state[1].
- __ mov(FieldOperand(state, ByteArray::kHeaderSize + kSeedSize), state1);
-
- // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF)
- Register random = state0;
- __ shl(random, 14);
- __ and_(state1, Immediate(0x3FFFF));
- __ add(random, state1);
-
- // Convert 32 random bits in random to 0.(32 random bits) in a double
- // by computing:
- // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
- XMMRegister result = ToDoubleRegister(instr->result());
- XMMRegister scratch4 = double_scratch0();
- __ mov(scratch3, Immediate(0x49800000)); // 1.0 x 2^20 as single.
- __ movd(scratch4, scratch3);
- __ movd(result, random);
- __ cvtss2sd(scratch4, scratch4);
- __ xorps(result, scratch4);
- __ subsd(result, scratch4);
-}
void LCodeGen::DoMathLog(LMathLog* instr) {
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-ia32.cc Wed Nov 20 12:43:33
2013 UTC
+++ /branches/bleeding_edge/src/ia32/lithium-ia32.cc Thu Nov 21 09:55:15
2013 UTC
@@ -1693,19 +1693,6 @@
return MarkAsCall(DefineFixedDouble(result, xmm3), instr,
CAN_DEOPTIMIZE_EAGERLY);
}
-
-
-LInstruction* LChunkBuilder::DoRandom(HRandom* instr) {
- ASSERT(instr->representation().IsDouble());
- ASSERT(instr->global_object()->representation().IsTagged());
- LOperand* global_object = UseTempRegister(instr->global_object());
- LOperand* scratch = TempRegister();
- LOperand* scratch2 = TempRegister();
- LOperand* scratch3 = TempRegister();
- LRandom* result = new(zone()) LRandom(
- global_object, scratch, scratch2, scratch3);
- return DefineFixedDouble(result, xmm1);
-}
LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-ia32.h Tue Nov 19 16:41:07
2013 UTC
+++ /branches/bleeding_edge/src/ia32/lithium-ia32.h Thu Nov 21 09:55:15
2013 UTC
@@ -154,7 +154,6 @@
V(OuterContext) \
V(Parameter) \
V(Power) \
- V(Random) \
V(PushArgument) \
V(RegExpLiteral) \
V(Return) \
@@ -1462,28 +1461,6 @@
};
-class LRandom V8_FINAL : public LTemplateInstruction<1, 1, 3> {
- public:
- LRandom(LOperand* global_object,
- LOperand* scratch,
- LOperand* scratch2,
- LOperand* scratch3) {
- inputs_[0] = global_object;
- temps_[0] = scratch;
- temps_[1] = scratch2;
- temps_[2] = scratch3;
- }
-
- LOperand* global_object() const { return inputs_[0]; }
- LOperand* scratch() const { return temps_[0]; }
- LOperand* scratch2() const { return temps_[1]; }
- LOperand* scratch3() const { return temps_[2]; }
-
- DECLARE_CONCRETE_INSTRUCTION(Random, "random")
- DECLARE_HYDROGEN_ACCESSOR(Random)
-};
-
-
class LArithmeticD V8_FINAL : public LTemplateInstruction<1, 2, 0> {
public:
LArithmeticD(Token::Value op, LOperand* left, LOperand* right)
=======================================
--- /branches/bleeding_edge/src/math.js Wed Nov 20 15:04:37 2013 UTC
+++ /branches/bleeding_edge/src/math.js Thu Nov 21 09:55:15 2013 UTC
@@ -168,8 +168,15 @@
}
// ECMA 262 - 15.8.2.14
+var rngstate; // Initialized to a Uint32Array during genesis.
function MathRandom() {
- return %_RandomHeapNumber();
+ var r0 = (MathImul(18273, rngstate[0] & 0xFFFF) + (rngstate[0] >>> 16))
| 0;
+ rngstate[0] = r0;
+ var r1 = (MathImul(36969, rngstate[1] & 0xFFFF) + (rngstate[1] >>> 16))
| 0;
+ rngstate[1] = r1;
+ var x = ((r0 << 14) + (r1 & 0x3FFFF)) | 0;
+ // Division by 0x100000000 through multiplication by reciprocal.
+ return (x < 0 ? (x + 0x100000000) : x) * 2.3283064365386962890625e-10;
}
// ECMA 262 - 15.8.2.15
=======================================
--- /branches/bleeding_edge/src/mips/full-codegen-mips.cc Wed Nov 20
19:01:33 2013 UTC
+++ /branches/bleeding_edge/src/mips/full-codegen-mips.cc Thu Nov 21
09:55:15 2013 UTC
@@ -3376,48 +3376,6 @@
__ LoadRoot(v0, Heap::kUndefinedValueRootIndex);
context()->Plug(v0);
}
-
-
-void FullCodeGenerator::EmitRandomHeapNumber(CallRuntime* expr) {
- ASSERT(expr->arguments()->length() == 0);
- Label slow_allocate_heapnumber;
- Label heapnumber_allocated;
-
- // Save the new heap number in callee-saved register s0, since
- // we call out to external C code below.
- __ LoadRoot(t6, Heap::kHeapNumberMapRootIndex);
- __ AllocateHeapNumber(s0, a1, a2, t6, &slow_allocate_heapnumber);
- __ jmp(&heapnumber_allocated);
-
- __ bind(&slow_allocate_heapnumber);
-
- // Allocate a heap number.
- __ CallRuntime(Runtime::kNumberAlloc, 0);
- __ mov(s0, v0); // Save result in s0, so it is saved thru CFunc call.
-
- __ bind(&heapnumber_allocated);
-
- // Convert 32 random bits in v0 to 0.(32 random bits) in a double
- // by computing:
- // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
- __ PrepareCallCFunction(1, a0);
- __ lw(a0, ContextOperand(cp, Context::GLOBAL_OBJECT_INDEX));
- __ lw(a0, FieldMemOperand(a0, GlobalObject::kNativeContextOffset));
- __ CallCFunction(ExternalReference::random_uint32_function(isolate()),
1);
-
- // 0x41300000 is the top half of 1.0 x 2^20 as a double.
- __ li(a1, Operand(0x41300000));
- // Move 0x41300000xxxxxxxx (x = random bits in v0) to FPU.
- __ Move(f12, v0, a1);
- // Move 0x4130000000000000 to FPU.
- __ Move(f14, zero_reg, a1);
- // Subtract and store the result in the heap number.
- __ sub_d(f0, f12, f14);
- __ sdc1(f0, FieldMemOperand(s0, HeapNumber::kValueOffset));
- __ mov(v0, s0);
-
- context()->Plug(v0);
-}
void FullCodeGenerator::EmitSubString(CallRuntime* expr) {
=======================================
--- /branches/bleeding_edge/src/mips/lithium-codegen-mips.cc Wed Nov 20
19:01:33 2013 UTC
+++ /branches/bleeding_edge/src/mips/lithium-codegen-mips.cc Thu Nov 21
09:55:15 2013 UTC
@@ -3827,68 +3827,6 @@
__ CallStub(&stub);
}
}
-
-
-void LCodeGen::DoRandom(LRandom* instr) {
- // Assert that the register size is indeed the size of each seed.
- static const int kSeedSize = sizeof(uint32_t);
- STATIC_ASSERT(kPointerSize == kSeedSize);
-
- // Load native context.
- Register global_object = ToRegister(instr->global_object());
- Register native_context = global_object;
- __ lw(native_context, FieldMemOperand(
- global_object, GlobalObject::kNativeContextOffset));
-
- // Load state (FixedArray of the native context's random seeds).
- static const int kRandomSeedOffset =
- FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize;
- Register state = native_context;
- __ lw(state, FieldMemOperand(native_context, kRandomSeedOffset));
-
- // Load state[0].
- Register state0 = ToRegister(instr->scratch());
- __ lw(state0, FieldMemOperand(state, ByteArray::kHeaderSize));
- // Load state[1].
- Register state1 = ToRegister(instr->scratch2());
- __ lw(state1, FieldMemOperand(state, ByteArray::kHeaderSize +
kSeedSize));
-
- // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16)
- Register scratch3 = ToRegister(instr->scratch3());
- Register scratch4 = scratch0();
- __ And(scratch3, state0, Operand(0xFFFF));
- __ li(scratch4, Operand(18273));
- __ Mul(scratch3, scratch3, scratch4);
- __ srl(state0, state0, 16);
- __ Addu(state0, scratch3, state0);
- // Save state[0].
- __ sw(state0, FieldMemOperand(state, ByteArray::kHeaderSize));
-
- // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16)
- __ And(scratch3, state1, Operand(0xFFFF));
- __ li(scratch4, Operand(36969));
- __ Mul(scratch3, scratch3, scratch4);
- __ srl(state1, state1, 16),
- __ Addu(state1, scratch3, state1);
- // Save state[1].
- __ sw(state1, FieldMemOperand(state, ByteArray::kHeaderSize +
kSeedSize));
-
- // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF)
- Register random = scratch4;
- __ And(random, state1, Operand(0x3FFFF));
- __ sll(state0, state0, 14);
- __ Addu(random, random, state0);
-
- // 0x41300000 is the top half of 1.0 x 2^20 as a double.
- __ li(scratch3, Operand(0x41300000));
- // Move 0x41300000xxxxxxxx (x = random bits in v0) to FPU.
- DoubleRegister result = ToDoubleRegister(instr->result());
- __ Move(result, random, scratch3);
- // Move 0x4130000000000000 to FPU.
- DoubleRegister scratch5 = double_scratch0();
- __ Move(scratch5, zero_reg, scratch3);
- __ sub_d(result, result, scratch5);
-}
void LCodeGen::DoMathExp(LMathExp* instr) {
=======================================
--- /branches/bleeding_edge/src/mips/lithium-mips.cc Wed Nov 20 17:02:12
2013 UTC
+++ /branches/bleeding_edge/src/mips/lithium-mips.cc Thu Nov 21 09:55:15
2013 UTC
@@ -1638,19 +1638,6 @@
instr,
CAN_DEOPTIMIZE_EAGERLY);
}
-
-
-LInstruction* LChunkBuilder::DoRandom(HRandom* instr) {
- ASSERT(instr->representation().IsDouble());
- ASSERT(instr->global_object()->representation().IsTagged());
- LOperand* global_object = UseTempRegister(instr->global_object());
- LOperand* scratch = TempRegister();
- LOperand* scratch2 = TempRegister();
- LOperand* scratch3 = TempRegister();
- LRandom* result = new(zone()) LRandom(
- global_object, scratch, scratch2, scratch3);
- return DefineFixedDouble(result, f0);
-}
LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
=======================================
--- /branches/bleeding_edge/src/mips/lithium-mips.h Tue Nov 19 22:23:41
2013 UTC
+++ /branches/bleeding_edge/src/mips/lithium-mips.h Thu Nov 21 09:55:15
2013 UTC
@@ -154,7 +154,6 @@
V(Parameter) \
V(Power) \
V(PushArgument) \
- V(Random) \
V(RegExpLiteral) \
V(Return) \
V(SeqStringGetChar) \
@@ -1461,28 +1460,6 @@
};
-class LRandom V8_FINAL : public LTemplateInstruction<1, 1, 3> {
- public:
- LRandom(LOperand* global_object,
- LOperand* scratch,
- LOperand* scratch2,
- LOperand* scratch3) {
- inputs_[0] = global_object;
- temps_[0] = scratch;
- temps_[1] = scratch2;
- temps_[2] = scratch3;
- }
-
- LOperand* global_object() const { return inputs_[0]; }
- LOperand* scratch() const { return temps_[0]; }
- LOperand* scratch2() const { return temps_[1]; }
- LOperand* scratch3() const { return temps_[2]; }
-
- DECLARE_CONCRETE_INSTRUCTION(Random, "random")
- DECLARE_HYDROGEN_ACCESSOR(Random)
-};
-
-
class LArithmeticD V8_FINAL : public LTemplateInstruction<1, 2, 0> {
public:
LArithmeticD(Token::Value op, LOperand* left, LOperand* right)
=======================================
--- /branches/bleeding_edge/src/objects.h Tue Nov 19 16:41:07 2013 UTC
+++ /branches/bleeding_edge/src/objects.h Thu Nov 21 09:55:15 2013 UTC
@@ -6506,7 +6506,6 @@
V(Math, exp, MathExp) \
V(Math, sqrt, MathSqrt) \
V(Math, pow, MathPow) \
- V(Math, random, MathRandom) \
V(Math, max, MathMax) \
V(Math, min, MathMin) \
V(Math, imul, MathImul)
=======================================
--- /branches/bleeding_edge/src/runtime.h Tue Nov 19 16:41:07 2013 UTC
+++ /branches/bleeding_edge/src/runtime.h Thu Nov 21 09:55:15 2013 UTC
@@ -623,7 +623,6 @@
F(OneByteSeqStringSetChar, 3,
1) \
F(TwoByteSeqStringSetChar, 3,
1) \
F(ObjectEquals, 2,
1) \
- F(RandomHeapNumber, 0,
1) \
F(IsObject, 1,
1) \
F(IsFunction, 1,
1) \
F(IsUndetectableObject, 1,
1) \
=======================================
--- /branches/bleeding_edge/src/serialize.cc Fri Nov 15 13:49:41 2013 UTC
+++ /branches/bleeding_edge/src/serialize.cc Thu Nov 21 09:55:15 2013 UTC
@@ -297,10 +297,6 @@
RUNTIME_ENTRY,
1,
"Runtime::PerformGC");
- Add(ExternalReference::random_uint32_function(isolate).address(),
- RUNTIME_ENTRY,
- 3,
- "V8::Random");
Add(ExternalReference::delete_handle_scope_extensions(isolate).address(),
RUNTIME_ENTRY,
4,
=======================================
--- /branches/bleeding_edge/src/v8.cc Tue Nov 19 14:28:07 2013 UTC
+++ /branches/bleeding_edge/src/v8.cc Thu Nov 21 09:55:15 2013 UTC
@@ -107,25 +107,6 @@
ReturnAddressLocationResolver resolver) {
StackFrame::SetReturnAddressLocationResolver(resolver);
}
-
-
-// Used by JavaScript APIs
-uint32_t V8::Random(Context* context) {
- ASSERT(context->IsNativeContext());
- ByteArray* seed = context->random_seed();
- uint32_t* state =
reinterpret_cast<uint32_t*>(seed->GetDataStartAddress());
-
- // When we get here, the RNG must have been initialized,
- // see the Genesis constructor in file bootstrapper.cc.
- ASSERT_NE(0, state[0]);
- ASSERT_NE(0, state[1]);
-
- // Mix the bits. Never replaces state[i] with 0 if it is nonzero.
- state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16);
- state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16);
-
- return (state[0] << 14) + (state[1] & 0x3FFFF);
-}
void V8::AddCallCompletedCallback(CallCompletedCallback callback) {
=======================================
--- /branches/bleeding_edge/src/v8.h Tue Nov 19 14:28:07 2013 UTC
+++ /branches/bleeding_edge/src/v8.h Thu Nov 21 09:55:15 2013 UTC
@@ -95,8 +95,6 @@
ReturnAddressLocationResolver resolver);
// Support for entry hooking JITed code.
static void SetFunctionEntryHook(FunctionEntryHook entry_hook);
- // Random number generation support. Not cryptographically safe.
- static uint32_t Random(Context* context);
static void AddCallCompletedCallback(CallCompletedCallback callback);
static void RemoveCallCompletedCallback(CallCompletedCallback callback);
=======================================
--- /branches/bleeding_edge/src/x64/full-codegen-x64.cc Wed Nov 20 14:17:47
2013 UTC
+++ /branches/bleeding_edge/src/x64/full-codegen-x64.cc Thu Nov 21 09:55:15
2013 UTC
@@ -3269,47 +3269,6 @@
__ LoadRoot(rax, Heap::kUndefinedValueRootIndex);
context()->Plug(rax);
}
-
-
-void FullCodeGenerator::EmitRandomHeapNumber(CallRuntime* expr) {
- ASSERT(expr->arguments()->length() == 0);
-
- Label slow_allocate_heapnumber;
- Label heapnumber_allocated;
-
- __ AllocateHeapNumber(rbx, rcx, &slow_allocate_heapnumber);
- __ jmp(&heapnumber_allocated);
-
- __ bind(&slow_allocate_heapnumber);
- // Allocate a heap number.
- __ CallRuntime(Runtime::kNumberAlloc, 0);
- __ movq(rbx, rax);
-
- __ bind(&heapnumber_allocated);
-
- // Return a random uint32 number in rax.
- // The fresh HeapNumber is in rbx, which is callee-save on both x64 ABIs.
- __ PrepareCallCFunction(1);
- __ movq(arg_reg_1,
- ContextOperand(context_register(),
Context::GLOBAL_OBJECT_INDEX));
- __ movq(arg_reg_1,
- FieldOperand(arg_reg_1, GlobalObject::kNativeContextOffset));
- __ CallCFunction(ExternalReference::random_uint32_function(isolate()),
1);
-
- // Convert 32 random bits in rax to 0.(32 random bits) in a double
- // by computing:
- // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
- __ movl(rcx, Immediate(0x49800000)); // 1.0 x 2^20 as single.
- __ movd(xmm1, rcx);
- __ movd(xmm0, rax);
- __ cvtss2sd(xmm1, xmm1);
- __ xorps(xmm0, xmm1);
- __ subsd(xmm0, xmm1);
- __ movsd(FieldOperand(rbx, HeapNumber::kValueOffset), xmm0);
-
- __ movq(rax, rbx);
- context()->Plug(rax);
-}
void FullCodeGenerator::EmitSubString(CallRuntime* expr) {
=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Wed Nov 20
12:43:33 2013 UTC
+++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Thu Nov 21
09:55:15 2013 UTC
@@ -3696,66 +3696,6 @@
__ CallStub(&stub);
}
}
-
-
-void LCodeGen::DoRandom(LRandom* instr) {
- // Assert that register size is twice the size of each seed.
- static const int kSeedSize = sizeof(uint32_t);
- STATIC_ASSERT(kPointerSize == 2 * kSeedSize);
-
- // Load native context
- Register global_object = ToRegister(instr->global_object());
- Register native_context = global_object;
- __ movq(native_context, FieldOperand(
- global_object, GlobalObject::kNativeContextOffset));
-
- // Load state (FixedArray of the native context's random seeds)
- static const int kRandomSeedOffset =
- FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize;
- Register state = native_context;
- __ movq(state, FieldOperand(native_context, kRandomSeedOffset));
-
- // Load state[0].
- Register state0 = ToRegister(instr->scratch());
- __ movl(state0, FieldOperand(state, ByteArray::kHeaderSize));
- // Load state[1].
- Register state1 = ToRegister(instr->scratch2());
- __ movl(state1, FieldOperand(state, ByteArray::kHeaderSize + kSeedSize));
-
- // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16)
- Register scratch3 = ToRegister(instr->scratch3());
- __ movzxwl(scratch3, state0);
- __ imull(scratch3, scratch3, Immediate(18273));
- __ shrl(state0, Immediate(16));
- __ addl(state0, scratch3);
- // Save state[0].
- __ movl(FieldOperand(state, ByteArray::kHeaderSize), state0);
-
- // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16)
- __ movzxwl(scratch3, state1);
- __ imull(scratch3, scratch3, Immediate(36969));
- __ shrl(state1, Immediate(16));
- __ addl(state1, scratch3);
- // Save state[1].
- __ movl(FieldOperand(state, ByteArray::kHeaderSize + kSeedSize), state1);
-
- // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF)
- Register random = state0;
- __ shll(random, Immediate(14));
- __ andl(state1, Immediate(0x3FFFF));
- __ addl(random, state1);
-
- // Convert 32 random bits in rax to 0.(32 random bits) in a double
- // by computing:
- // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
- XMMRegister result = ToDoubleRegister(instr->result());
- XMMRegister scratch4 = double_scratch0();
- __ movq(scratch3, V8_INT64_C(0x4130000000000000)); // 1.0 x 2^20 as
double
- __ movq(scratch4, scratch3);
- __ movd(result, random);
- __ xorps(result, scratch4);
- __ subsd(result, scratch4);
-}
void LCodeGen::DoMathExp(LMathExp* instr) {
=======================================
--- /branches/bleeding_edge/src/x64/lithium-x64.cc Wed Nov 20 12:43:33 2013
UTC
+++ /branches/bleeding_edge/src/x64/lithium-x64.cc Thu Nov 21 09:55:15 2013
UTC
@@ -1599,19 +1599,6 @@
return MarkAsCall(DefineFixedDouble(result, xmm3), instr,
CAN_DEOPTIMIZE_EAGERLY);
}
-
-
-LInstruction* LChunkBuilder::DoRandom(HRandom* instr) {
- ASSERT(instr->representation().IsDouble());
- ASSERT(instr->global_object()->representation().IsTagged());
- LOperand* global_object = UseTempRegister(instr->global_object());
- LOperand* scratch = TempRegister();
- LOperand* scratch2 = TempRegister();
- LOperand* scratch3 = TempRegister();
- LRandom* result = new(zone()) LRandom(
- global_object, scratch, scratch2, scratch3);
- return DefineFixedDouble(result, xmm1);
-}
LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) {
=======================================
--- /branches/bleeding_edge/src/x64/lithium-x64.h Tue Nov 19 16:41:07 2013
UTC
+++ /branches/bleeding_edge/src/x64/lithium-x64.h Thu Nov 21 09:55:15 2013
UTC
@@ -153,7 +153,6 @@
V(Parameter) \
V(Power) \
V(PushArgument) \
- V(Random) \
V(RegExpLiteral) \
V(Return) \
V(SeqStringGetChar) \
@@ -1424,28 +1423,6 @@
};
-class LRandom V8_FINAL : public LTemplateInstruction<1, 1, 3> {
- public:
- LRandom(LOperand* global_object,
- LOperand* scratch,
- LOperand* scratch2,
- LOperand* scratch3) {
- inputs_[0] = global_object;
- temps_[0] = scratch;
- temps_[1] = scratch2;
- temps_[2] = scratch3;
- }
-
- LOperand* global_object() { return inputs_[0]; }
- LOperand* scratch() const { return temps_[0]; }
- LOperand* scratch2() const { return temps_[1]; }
- LOperand* scratch3() const { return temps_[2]; }
-
- DECLARE_CONCRETE_INSTRUCTION(Random, "random")
- DECLARE_HYDROGEN_ACCESSOR(Random)
-};
-
-
class LArithmeticD V8_FINAL : public LTemplateInstruction<1, 2, 0> {
public:
LArithmeticD(Token::Value op, LOperand* left, LOperand* right)
=======================================
--- /branches/bleeding_edge/test/cctest/test-weaktypedarrays.cc Mon Jun 24
11:23:50 2013 UTC
+++ /branches/bleeding_edge/test/cctest/test-weaktypedarrays.cc Thu Nov 21
09:55:15 2013 UTC
@@ -89,7 +89,7 @@
LocalContext context;
Isolate* isolate = GetIsolateFrom(&context);
- CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap()));
+ int start = CountArrayBuffersInWeakList(isolate->heap());
{
v8::HandleScope s1(context->GetIsolate());
v8::Handle<v8::ArrayBuffer> ab1 = v8::ArrayBuffer::New(256);
@@ -99,12 +99,12 @@
Handle<JSArrayBuffer> iab1 = v8::Utils::OpenHandle(*ab1);
Handle<JSArrayBuffer> iab2 = v8::Utils::OpenHandle(*ab2);
- CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->heap()));
+ CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->heap()) - start);
CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab1));
CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab2));
}
isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
- CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()));
+ CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start);
{
HandleScope scope2(isolate);
Handle<JSArrayBuffer> iab1 = v8::Utils::OpenHandle(*ab1);
@@ -114,7 +114,7 @@
}
isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
- CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap()));
+ CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap()) - start);
}
@@ -122,11 +122,12 @@
v8::V8::Initialize();
LocalContext context;
Isolate* isolate = GetIsolateFrom(&context);
+ int start = CountArrayBuffersInWeakList(isolate->heap());
for (int i = 1; i <= 3; i++) {
// Create 3 array buffers, make i-th of them garbage,
// validate correct state of array buffer weak list.
- CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap()));
+ CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap()) - start);
{
v8::HandleScope scope(context->GetIsolate());
@@ -142,7 +143,7 @@
v8::Handle<v8::ArrayBuffer> ab3 =
v8::Handle<v8::ArrayBuffer>::Cast(CompileRun("ab3"));
- CHECK_EQ(3, CountArrayBuffersInWeakList(isolate->heap()));
+ CHECK_EQ(3, CountArrayBuffersInWeakList(isolate->heap()) - start);
CHECK(HasArrayBufferInWeakList(isolate->heap(),
*v8::Utils::OpenHandle(*ab1)));
CHECK(HasArrayBufferInWeakList(isolate->heap(),
@@ -156,7 +157,7 @@
CompileRun(source.start());
isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
- CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->heap()));
+ CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->heap()) - start);
{
v8::HandleScope s2(context->GetIsolate());
@@ -174,7 +175,7 @@
}
isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
- CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap()));
+ CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap()) - start);
}
}
@@ -266,6 +267,7 @@
LocalContext context;
Isolate* isolate = GetIsolateFrom(&context);
v8::HandleScope scope(context->GetIsolate());
+ int start = CountArrayBuffersInWeakList(isolate->heap());
CompileRun("var ab = new ArrayBuffer(2048);");
for (int i = 1; i <= 3; i++) {
// Create 3 typed arrays, make i-th of them garbage,
@@ -273,7 +275,7 @@
v8::HandleScope s0(context->GetIsolate());
i::ScopedVector<char> source(2048);
- CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()));
+ CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start);
{
v8::HandleScope s1(context->GetIsolate());
@@ -292,7 +294,7 @@
v8::Handle<TypedArray>::Cast(CompileRun("ta2"));
v8::Handle<TypedArray> ta3 =
v8::Handle<TypedArray>::Cast(CompileRun("ta3"));
- CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()));
+ CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start);
Handle<JSArrayBuffer> iab = v8::Utils::OpenHandle(*ab);
CHECK_EQ(3, CountViews(*iab));
CHECK(HasViewInWeakList(*iab, *v8::Utils::OpenHandle(*ta1)));
@@ -304,7 +306,7 @@
CompileRun(source.start());
isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
- CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()));
+ CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start);
{
v8::HandleScope s2(context->GetIsolate());
@@ -324,7 +326,7 @@
CompileRun("ta1 = null; ta2 = null; ta3 = null;");
isolate->heap()->CollectAllGarbage(Heap::kAbortIncrementalMarkingMask);
- CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()));
+ CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()) - start);
{
v8::HandleScope s3(context->GetIsolate());
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.