diff --git a/deps/v8/ChangeLog b/deps/v8/ChangeLog index 07859597bf..69aff33d18 100644 --- a/deps/v8/ChangeLog +++ b/deps/v8/ChangeLog @@ -1,3 +1,12 @@ +2010-11-01: Version 2.5.3 + + Fixed a bug that prevents constants from overwriting function values + in object literals (issue 907). + + Fixed a bug with reporting of impossible nested calls of DOM functions + (issue http://crbug.com/60753). + + 2010-10-27: Version 2.5.2 Improved sampler resolution on Linux. diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index 89502cb915..c7e4552b4d 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -1790,18 +1790,19 @@ class Arguments { inline bool IsConstructCall() const; inline Local Data() const; private: + static const int kDataIndex = 0; + static const int kCalleeIndex = -1; + static const int kHolderIndex = -2; + friend class ImplementationUtilities; - inline Arguments(Local data, - Local holder, - Local callee, - bool is_construct_call, - void** values, int length); - Local data_; - Local holder_; - Local callee_; - bool is_construct_call_; - void** values_; + inline Arguments(internal::Object** implicit_args, + internal::Object** values, + int length, + bool is_construct_call); + internal::Object** implicit_args_; + internal::Object** values_; int length_; + bool is_construct_call_; }; @@ -3470,14 +3471,13 @@ void Persistent::ClearWeak() { } -Arguments::Arguments(v8::Local data, - v8::Local holder, - v8::Local callee, - bool is_construct_call, - void** values, int length) - : data_(data), holder_(holder), callee_(callee), - is_construct_call_(is_construct_call), - values_(values), length_(length) { } +Arguments::Arguments(internal::Object** implicit_args, + internal::Object** values, int length, + bool is_construct_call) + : implicit_args_(implicit_args), + values_(values), + length_(length), + is_construct_call_(is_construct_call) { } Local Arguments::operator[](int i) const { @@ -3487,7 +3487,8 @@ Local Arguments::operator[](int i) const { Local Arguments::Callee() const { - return callee_; + return Local(reinterpret_cast( + &implicit_args_[kCalleeIndex])); } @@ -3497,12 +3498,13 @@ Local Arguments::This() const { Local Arguments::Holder() const { - return holder_; + return Local(reinterpret_cast( + &implicit_args_[kHolderIndex])); } Local Arguments::Data() const { - return data_; + return Local(reinterpret_cast(&implicit_args_[kDataIndex])); } diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc index 2df31df353..617922dd5a 100644 --- a/deps/v8/src/api.cc +++ b/deps/v8/src/api.cc @@ -1155,13 +1155,13 @@ void ObjectTemplate::SetInternalFieldCount(int value) { ScriptData* ScriptData::PreCompile(const char* input, int length) { unibrow::Utf8InputBuffer<> buf(input, length); - return i::Parser::PreParse(i::Handle(), &buf, NULL); + return i::ParserApi::PreParse(i::Handle(), &buf, NULL); } ScriptData* ScriptData::PreCompile(v8::Handle source) { i::Handle str = Utils::OpenHandle(*source); - return i::Parser::PreParse(str, NULL, NULL); + return i::ParserApi::PreParse(str, NULL, NULL); } diff --git a/deps/v8/src/apiutils.h b/deps/v8/src/apiutils.h index 8c791ebdd5..1313ddaabe 100644 --- a/deps/v8/src/apiutils.h +++ b/deps/v8/src/apiutils.h @@ -29,7 +29,6 @@ #define V8_APIUTILS_H_ namespace v8 { - class ImplementationUtilities { public: static v8::Handle Undefined(); @@ -45,12 +44,21 @@ class ImplementationUtilities { return that->names_; } - static v8::Arguments NewArguments(Local data, - Local holder, - Local callee, - bool is_construct_call, - void** argv, int argc) { - return v8::Arguments(data, holder, callee, is_construct_call, argv, argc); + // Packs additional parameters for the NewArguments function. |implicit_args| + // is a pointer to the last element of 3-elements array controlled by GC. + static void PrepareArgumentsData(internal::Object** implicit_args, + internal::Object* data, + internal::JSFunction* callee, + internal::Object* holder) { + implicit_args[v8::Arguments::kDataIndex] = data; + implicit_args[v8::Arguments::kCalleeIndex] = callee; + implicit_args[v8::Arguments::kHolderIndex] = holder; + } + + static v8::Arguments NewArguments(internal::Object** implicit_args, + internal::Object** argv, int argc, + bool is_construct_call) { + return v8::Arguments(implicit_args, argv, argc, is_construct_call); } // Introduce an alias for the handle scope data to allow non-friends diff --git a/deps/v8/src/arguments.h b/deps/v8/src/arguments.h index c17f4cf80b..d51c9e4cb1 100644 --- a/deps/v8/src/arguments.h +++ b/deps/v8/src/arguments.h @@ -84,6 +84,15 @@ class CustomArguments : public Relocatable { values_[1] = holder; values_[0] = data; } + + inline CustomArguments() { +#ifdef DEBUG + for (size_t i = 0; i < ARRAY_SIZE(values_); i++) { + values_[i] = reinterpret_cast(kZapValue); + } +#endif + } + void IterateInstance(ObjectVisitor* v); Object** end() { return values_ + ARRAY_SIZE(values_) - 1; } private: diff --git a/deps/v8/src/arm/assembler-arm.cc b/deps/v8/src/arm/assembler-arm.cc index 7d368bf415..ebbd9b1138 100644 --- a/deps/v8/src/arm/assembler-arm.cc +++ b/deps/v8/src/arm/assembler-arm.cc @@ -1004,7 +1004,7 @@ void Assembler::blx(int branch_offset) { // v5 and above int h = ((branch_offset & 2) >> 1)*B24; int imm24 = branch_offset >> 2; ASSERT(is_int24(imm24)); - emit(15 << 28 | B27 | B25 | h | (imm24 & Imm24Mask)); + emit(nv | B27 | B25 | h | (imm24 & Imm24Mask)); } @@ -1634,15 +1634,29 @@ void Assembler::stm(BlockAddrMode am, // Exception-generating instructions and debugging support. -void Assembler::stop(const char* msg) { +// Stops with a non-negative code less than kNumOfWatchedStops support +// enabling/disabling and a counter feature. See simulator-arm.h . +void Assembler::stop(const char* msg, Condition cond, int32_t code) { #ifndef __arm__ - // The simulator handles these special instructions and stops execution. - emit(15 << 28 | ((intptr_t) msg)); + // See constants-arm.h SoftwareInterruptCodes. Unluckily the Assembler and + // Simulator do not share constants declaration. + ASSERT(code >= kDefaultStopCode); + static const uint32_t kStopInterruptCode = 1 << 23; + static const uint32_t kMaxStopCode = kStopInterruptCode - 1; + // The Simulator will handle the stop instruction and get the message address. + // It expects to find the address just after the svc instruction. + BlockConstPoolFor(2); + if (code >= 0) { + svc(kStopInterruptCode + code, cond); + } else { + svc(kStopInterruptCode + kMaxStopCode, cond); + } + emit(reinterpret_cast(msg)); #else // def __arm__ #ifdef CAN_USE_ARMV5_INSTRUCTIONS bkpt(0); #else // ndef CAN_USE_ARMV5_INSTRUCTIONS - swi(0x9f0001); + svc(0x9f0001); #endif // ndef CAN_USE_ARMV5_INSTRUCTIONS #endif // def __arm__ } @@ -1654,7 +1668,7 @@ void Assembler::bkpt(uint32_t imm16) { // v5 and above } -void Assembler::swi(uint32_t imm24, Condition cond) { +void Assembler::svc(uint32_t imm24, Condition cond) { ASSERT(is_uint24(imm24)); emit(cond | 15*B24 | imm24); } diff --git a/deps/v8/src/arm/assembler-arm.h b/deps/v8/src/arm/assembler-arm.h index 1c4fd6094d..5b647a7537 100644 --- a/deps/v8/src/arm/assembler-arm.h +++ b/deps/v8/src/arm/assembler-arm.h @@ -904,10 +904,13 @@ class Assembler : public Malloced { void stm(BlockAddrMode am, Register base, RegList src, Condition cond = al); // Exception-generating instructions and debugging support - void stop(const char* msg); + static const int kDefaultStopCode = -1; + void stop(const char* msg, + Condition cond = al, + int32_t code = kDefaultStopCode); void bkpt(uint32_t imm16); // v5 and above - void swi(uint32_t imm24, Condition cond = al); + void svc(uint32_t imm24, Condition cond = al); // Coprocessor instructions diff --git a/deps/v8/src/arm/codegen-arm.cc b/deps/v8/src/arm/codegen-arm.cc index 0c060f0f6f..70ff244649 100644 --- a/deps/v8/src/arm/codegen-arm.cc +++ b/deps/v8/src/arm/codegen-arm.cc @@ -3596,6 +3596,12 @@ void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) { frame_->CallRuntime(Runtime::kCreateObjectLiteralShallow, 4); } frame_->EmitPush(r0); // save the result + + // Mark all computed expressions that are bound to a key that + // is shadowed by a later occurrence of the same key. For the + // marked expressions, no store code is emitted. + node->CalculateEmitStore(); + for (int i = 0; i < node->properties()->length(); i++) { // At the start of each iteration, the top of stack contains // the newly created object literal. @@ -3612,11 +3618,15 @@ void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) { if (key->handle()->IsSymbol()) { Handle ic(Builtins::builtin(Builtins::StoreIC_Initialize)); Load(value); - frame_->PopToR0(); - // Fetch the object literal. - frame_->SpillAllButCopyTOSToR1(); - __ mov(r2, Operand(key->handle())); - frame_->CallCodeObject(ic, RelocInfo::CODE_TARGET, 0); + if (property->emit_store()) { + frame_->PopToR0(); + // Fetch the object literal. + frame_->SpillAllButCopyTOSToR1(); + __ mov(r2, Operand(key->handle())); + frame_->CallCodeObject(ic, RelocInfo::CODE_TARGET, 0); + } else { + frame_->Drop(); + } break; } // else fall through @@ -3624,7 +3634,11 @@ void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) { frame_->Dup(); Load(key); Load(value); - frame_->CallRuntime(Runtime::kSetProperty, 3); + if (property->emit_store()) { + frame_->CallRuntime(Runtime::kSetProperty, 3); + } else { + frame_->Drop(3); + } break; } case ObjectLiteral::Property::SETTER: { diff --git a/deps/v8/src/arm/constants-arm.h b/deps/v8/src/arm/constants-arm.h index b2b5cb56b0..123c5e7972 100644 --- a/deps/v8/src/arm/constants-arm.h +++ b/deps/v8/src/arm/constants-arm.h @@ -186,12 +186,18 @@ enum Shift { // Special Software Interrupt codes when used in the presence of the ARM // simulator. +// svc (formerly swi) provides a 24bit immediate value. Use bits 22:0 for +// standard SoftwareInterrupCode. Bit 23 is reserved for the stop feature. enum SoftwareInterruptCodes { // transition to C code call_rt_redirected = 0x10, // break point - break_point = 0x20 + break_point = 0x20, + // stop + stop = 1 << 23 }; +static const int32_t kStopCodeMask = stop - 1; +static const uint32_t kMaxStopCode = stop - 1; // Type of VFP register. Determines register encoding. @@ -325,7 +331,7 @@ class Instr { inline int SImmed24Field() const { return ((InstructionBits() << 8) >> 8); } // Fields used in Software interrupt instructions - inline SoftwareInterruptCodes SwiField() const { + inline SoftwareInterruptCodes SvcField() const { return static_cast(Bits(23, 0)); } diff --git a/deps/v8/src/arm/cpu-arm.cc b/deps/v8/src/arm/cpu-arm.cc index a3bf48328d..e998b6f596 100644 --- a/deps/v8/src/arm/cpu-arm.cc +++ b/deps/v8/src/arm/cpu-arm.cc @@ -70,7 +70,7 @@ void CPU::FlushICache(void* start, size_t size) { // __arm__ may be defined in thumb mode. register uint32_t scno asm("r7") = __ARM_NR_cacheflush; asm volatile( - "swi 0x0" + "svc 0x0" : "=r" (beg) : "0" (beg), "r" (end), "r" (flg), "r" (scno)); #else @@ -83,7 +83,7 @@ void CPU::FlushICache(void* start, size_t size) { ".ARM \n" "1: push {r7} \n\t" "mov r7, %4 \n\t" - "swi 0x0 \n\t" + "svc 0x0 \n\t" "pop {r7} \n\t" "@ Enter THUMB Mode\n\t" "adr r3, 2f+1 \n\t" @@ -98,20 +98,20 @@ void CPU::FlushICache(void* start, size_t size) { #if defined (__arm__) && !defined(__thumb__) // __arm__ may be defined in thumb mode. asm volatile( - "swi %1" + "svc %1" : "=r" (beg) : "i" (__ARM_NR_cacheflush), "0" (beg), "r" (end), "r" (flg)); #else // Do not use the value of __ARM_NR_cacheflush in the inline assembly // below, because the thumb mode value would be used, which would be - // wrong, since we switch to ARM mode before executing the swi instruction + // wrong, since we switch to ARM mode before executing the svc instruction asm volatile( "@ Enter ARM Mode \n\t" "adr r3, 1f \n\t" "bx r3 \n\t" ".ALIGN 4 \n\t" ".ARM \n" - "1: swi 0x9f0002 \n" + "1: svc 0x9f0002 \n" "@ Enter THUMB Mode\n\t" "adr r3, 2f+1 \n\t" "bx r3 \n\t" diff --git a/deps/v8/src/arm/disasm-arm.cc b/deps/v8/src/arm/disasm-arm.cc index 5122f437b9..4e7580f868 100644 --- a/deps/v8/src/arm/disasm-arm.cc +++ b/deps/v8/src/arm/disasm-arm.cc @@ -108,7 +108,7 @@ class Decoder { void PrintShiftImm(Instr* instr); void PrintShiftSat(Instr* instr); void PrintPU(Instr* instr); - void PrintSoftwareInterrupt(SoftwareInterruptCodes swi); + void PrintSoftwareInterrupt(SoftwareInterruptCodes svc); // Handle formatting of instructions and their options. int FormatRegister(Instr* instr, const char* option); @@ -126,8 +126,8 @@ class Decoder { void DecodeType4(Instr* instr); void DecodeType5(Instr* instr); void DecodeType6(Instr* instr); - void DecodeType7(Instr* instr); - void DecodeUnconditional(Instr* instr); + // Type 7 includes special Debugger instructions. + int DecodeType7(Instr* instr); // For VFP support. void DecodeTypeVFP(Instr* instr); void DecodeType6CoprocessorIns(Instr* instr); @@ -290,8 +290,8 @@ void Decoder::PrintPU(Instr* instr) { // Print SoftwareInterrupt codes. Factoring this out reduces the complexity of // the FormatOption method. -void Decoder::PrintSoftwareInterrupt(SoftwareInterruptCodes swi) { - switch (swi) { +void Decoder::PrintSoftwareInterrupt(SoftwareInterruptCodes svc) { + switch (svc) { case call_rt_redirected: Print("call_rt_redirected"); return; @@ -299,9 +299,16 @@ void Decoder::PrintSoftwareInterrupt(SoftwareInterruptCodes swi) { Print("break_point"); return; default: - out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, - "%d", - swi); + if (svc >= stop) { + out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, + "%d - 0x%x", + svc & kStopCodeMask, + svc & kStopCodeMask); + } else { + out_buffer_pos_ += v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, + "%d", + svc); + } return; } } @@ -553,9 +560,9 @@ int Decoder::FormatOption(Instr* instr, const char* format) { PrintShiftRm(instr); return 8; } - } else if (format[1] == 'w') { // 'swi - ASSERT(STRING_STARTS_WITH(format, "swi")); - PrintSoftwareInterrupt(instr->SwiField()); + } else if (format[1] == 'v') { // 'svc + ASSERT(STRING_STARTS_WITH(format, "svc")); + PrintSoftwareInterrupt(instr->SvcField()); return 3; } else if (format[1] == 'i') { // 'sign: signed extra loads and stores ASSERT(STRING_STARTS_WITH(format, "sign")); @@ -1004,72 +1011,27 @@ void Decoder::DecodeType6(Instr* instr) { } -void Decoder::DecodeType7(Instr* instr) { +int Decoder::DecodeType7(Instr* instr) { if (instr->Bit(24) == 1) { - Format(instr, "swi'cond 'swi"); + if (instr->SvcField() >= stop) { + Format(instr, "stop'cond 'svc"); + // Also print the stop message. Its address is encoded + // in the following 4 bytes. + out_buffer_pos_ += + v8i::OS::SNPrintF(out_buffer_ + out_buffer_pos_, + "\n %p %08x stop message: %s", + reinterpret_cast(instr + Instr::kInstrSize), + *reinterpret_cast(instr + Instr::kInstrSize), + *reinterpret_cast(instr + Instr::kInstrSize)); + // We have decoded 2 * Instr::kInstrSize bytes. + return 2 * Instr::kInstrSize; + } else { + Format(instr, "svc'cond 'svc"); + } } else { DecodeTypeVFP(instr); } -} - -void Decoder::DecodeUnconditional(Instr* instr) { - if (instr->Bits(7, 4) == 0xB && instr->Bits(27, 25) == 0 && instr->HasL()) { - Format(instr, "'memop'h'pu 'rd, "); - bool immediate = instr->HasB(); - switch (instr->PUField()) { - case 0: { - // Post index, negative. - if (instr->HasW()) { - Unknown(instr); - break; - } - if (immediate) { - Format(instr, "['rn], #-'imm12"); - } else { - Format(instr, "['rn], -'rm"); - } - break; - } - case 1: { - // Post index, positive. - if (instr->HasW()) { - Unknown(instr); - break; - } - if (immediate) { - Format(instr, "['rn], #+'imm12"); - } else { - Format(instr, "['rn], +'rm"); - } - break; - } - case 2: { - // Pre index or offset, negative. - if (immediate) { - Format(instr, "['rn, #-'imm12]'w"); - } else { - Format(instr, "['rn, -'rm]'w"); - } - break; - } - case 3: { - // Pre index or offset, positive. - if (immediate) { - Format(instr, "['rn, #+'imm12]'w"); - } else { - Format(instr, "['rn, +'rm]'w"); - } - break; - } - default: { - // The PU field is a 2-bit field. - UNREACHABLE(); - break; - } - } - return; - } - Format(instr, "break 'msg"); + return Instr::kInstrSize; } @@ -1332,7 +1294,7 @@ int Decoder::InstructionDecode(byte* instr_ptr) { "%08x ", instr->InstructionBits()); if (instr->ConditionField() == special_condition) { - DecodeUnconditional(instr); + UNIMPLEMENTED(); return Instr::kInstrSize; } switch (instr->TypeField()) { @@ -1362,8 +1324,7 @@ int Decoder::InstructionDecode(byte* instr_ptr) { break; } case 7: { - DecodeType7(instr); - break; + return DecodeType7(instr); } default: { // The type field is 3-bits in the ARM encoding. diff --git a/deps/v8/src/arm/full-codegen-arm.cc b/deps/v8/src/arm/full-codegen-arm.cc index 2855ca4f3b..9935e038f5 100644 --- a/deps/v8/src/arm/full-codegen-arm.cc +++ b/deps/v8/src/arm/full-codegen-arm.cc @@ -1169,6 +1169,11 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { // result_saved is false the result is in r0. bool result_saved = false; + // Mark all computed expressions that are bound to a key that + // is shadowed by a later occurrence of the same key. For the + // marked expressions, no store code is emitted. + expr->CalculateEmitStore(); + for (int i = 0; i < expr->properties()->length(); i++) { ObjectLiteral::Property* property = expr->properties()->at(i); if (property->IsCompileTimeValue()) continue; @@ -1190,8 +1195,10 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { VisitForAccumulatorValue(value); __ mov(r2, Operand(key->handle())); __ ldr(r1, MemOperand(sp)); - Handle ic(Builtins::builtin(Builtins::StoreIC_Initialize)); - EmitCallIC(ic, RelocInfo::CODE_TARGET); + if (property->emit_store()) { + Handle ic(Builtins::builtin(Builtins::StoreIC_Initialize)); + EmitCallIC(ic, RelocInfo::CODE_TARGET); + } break; } // Fall through. @@ -1201,7 +1208,11 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { __ push(r0); VisitForStackValue(key); VisitForStackValue(value); - __ CallRuntime(Runtime::kSetProperty, 3); + if (property->emit_store()) { + __ CallRuntime(Runtime::kSetProperty, 3); + } else { + __ Drop(3); + } break; case ObjectLiteral::Property::GETTER: case ObjectLiteral::Property::SETTER: diff --git a/deps/v8/src/arm/ic-arm.cc b/deps/v8/src/arm/ic-arm.cc index c460f9ca6f..a09afdf754 100644 --- a/deps/v8/src/arm/ic-arm.cc +++ b/deps/v8/src/arm/ic-arm.cc @@ -544,7 +544,7 @@ static void GenerateMonomorphicCacheProbe(MacroAssembler* masm, // Probe the stub cache. Code::Flags flags = Code::ComputeFlags(kind, NOT_IN_LOOP, MONOMORPHIC, NORMAL, argc); - StubCache::GenerateProbe(masm, flags, r1, r2, r3, no_reg); + StubCache::GenerateProbe(masm, flags, r1, r2, r3, r4, r5); // If the stub cache probing failed, the receiver might be a value. // For value objects, we use the map of the prototype objects for @@ -583,7 +583,7 @@ static void GenerateMonomorphicCacheProbe(MacroAssembler* masm, // Probe the stub cache for the value object. __ bind(&probe); - StubCache::GenerateProbe(masm, flags, r1, r2, r3, no_reg); + StubCache::GenerateProbe(masm, flags, r1, r2, r3, r4, r5); __ bind(&miss); } @@ -858,7 +858,7 @@ void LoadIC::GenerateMegamorphic(MacroAssembler* masm) { Code::Flags flags = Code::ComputeFlags(Code::LOAD_IC, NOT_IN_LOOP, MONOMORPHIC); - StubCache::GenerateProbe(masm, flags, r0, r2, r3, no_reg); + StubCache::GenerateProbe(masm, flags, r0, r2, r3, r4, r5); // Cache miss: Jump to runtime. GenerateMiss(masm); @@ -2163,7 +2163,7 @@ void StoreIC::GenerateMegamorphic(MacroAssembler* masm) { Code::Flags flags = Code::ComputeFlags(Code::STORE_IC, NOT_IN_LOOP, MONOMORPHIC); - StubCache::GenerateProbe(masm, flags, r1, r2, r3, no_reg); + StubCache::GenerateProbe(masm, flags, r1, r2, r3, r4, r5); // Cache miss: Jump to runtime. GenerateMiss(masm); diff --git a/deps/v8/src/arm/simulator-arm.cc b/deps/v8/src/arm/simulator-arm.cc index 534e394af1..cb91520f3a 100644 --- a/deps/v8/src/arm/simulator-arm.cc +++ b/deps/v8/src/arm/simulator-arm.cc @@ -112,15 +112,29 @@ static void InitializeCoverage() { void Debugger::Stop(Instr* instr) { - char* str = reinterpret_cast(instr->InstructionBits() & 0x0fffffff); - if (strlen(str) > 0) { + // Get the stop code. + uint32_t code = instr->SvcField() & kStopCodeMask; + // Retrieve the encoded address, which comes just after this stop. + char** msg_address = + reinterpret_cast(sim_->get_pc() + Instr::kInstrSize); + char* msg = *msg_address; + ASSERT(msg != NULL); + + // Update this stop description. + if (isWatchedStop(code) && !watched_stops[code].desc) { + watched_stops[code].desc = msg; + } + + if (strlen(msg) > 0) { if (coverage_log != NULL) { - fprintf(coverage_log, "%s\n", str); + fprintf(coverage_log, "%s\n", msg); fflush(coverage_log); } - instr->SetInstructionBits(0xe1a00000); // Overwrite with nop. + // Overwrite the instruction and address with nops. + instr->SetInstructionBits(kNopInstr); + reinterpret_cast(msg_address)->SetInstructionBits(kNopInstr); } - sim_->set_pc(sim_->get_pc() + Instr::kInstrSize); + sim_->set_pc(sim_->get_pc() + 2 * Instr::kInstrSize); } #else // ndef GENERATED_CODE_COVERAGE @@ -130,9 +144,16 @@ static void InitializeCoverage() { void Debugger::Stop(Instr* instr) { - const char* str = (const char*)(instr->InstructionBits() & 0x0fffffff); - PrintF("Simulator hit %s\n", str); - sim_->set_pc(sim_->get_pc() + Instr::kInstrSize); + // Get the stop code. + uint32_t code = instr->SvcField() & kStopCodeMask; + // Retrieve the encoded address, which comes just after this stop. + char* msg = *reinterpret_cast(sim_->get_pc() + Instr::kInstrSize); + // Update this stop description. + if (sim_->isWatchedStop(code) && !sim_->watched_stops[code].desc) { + sim_->watched_stops[code].desc = msg; + } + PrintF("Simulator hit %s\n", msg); + sim_->set_pc(sim_->get_pc() + 2 * Instr::kInstrSize); Debug(); } #endif @@ -359,6 +380,7 @@ void Debugger::Debug() { // use a reasonably large buffer v8::internal::EmbeddedVector buffer; + byte* prev = NULL; byte* cur = NULL; byte* end = NULL; @@ -368,9 +390,9 @@ void Debugger::Debug() { } else if (argc == 2) { int32_t value; if (GetValue(arg1, &value)) { - cur = reinterpret_cast(value); - // no length parameter passed, assume 10 instructions - end = cur + (10 * Instr::kInstrSize); + cur = reinterpret_cast(sim_->get_pc()); + // Disassemble instructions. + end = cur + (value * Instr::kInstrSize); } } else { int32_t value1; @@ -382,10 +404,10 @@ void Debugger::Debug() { } while (cur < end) { - dasm.InstructionDecode(buffer, cur); + prev = cur; + cur += dasm.InstructionDecode(buffer, cur); PrintF(" 0x%08x %s\n", - reinterpret_cast(cur), buffer.start()); - cur += Instr::kInstrSize; + reinterpret_cast(prev), buffer.start()); } } else if (strcmp(cmd, "gdb") == 0) { PrintF("relinquishing control to gdb\n"); @@ -418,13 +440,58 @@ void Debugger::Debug() { PrintF("OVERFLOW flag: %d; ", sim_->overflow_vfp_flag_); PrintF("UNDERFLOW flag: %d; ", sim_->underflow_vfp_flag_); PrintF("INEXACT flag: %d; ", sim_->inexact_vfp_flag_); - } else if (strcmp(cmd, "unstop") == 0) { - intptr_t stop_pc = sim_->get_pc() - Instr::kInstrSize; + } else if (strcmp(cmd, "stop") == 0) { + int32_t value; + intptr_t stop_pc = sim_->get_pc() - 2 * Instr::kInstrSize; Instr* stop_instr = reinterpret_cast(stop_pc); - if (stop_instr->ConditionField() == special_condition) { - stop_instr->SetInstructionBits(kNopInstr); + Instr* msg_address = + reinterpret_cast(stop_pc + Instr::kInstrSize); + if ((argc == 2) && (strcmp(arg1, "unstop") == 0)) { + // Remove the current stop. + if (sim_->isStopInstruction(stop_instr)) { + stop_instr->SetInstructionBits(kNopInstr); + msg_address->SetInstructionBits(kNopInstr); + } else { + PrintF("Not at debugger stop.\n"); + } + } else if (argc == 3) { + // Print information about all/the specified breakpoint(s). + if (strcmp(arg1, "info") == 0) { + if (strcmp(arg2, "all") == 0) { + PrintF("Stop information:\n"); + for (uint32_t i = 0; i < sim_->kNumOfWatchedStops; i++) { + sim_->PrintStopInfo(i); + } + } else if (GetValue(arg2, &value)) { + sim_->PrintStopInfo(value); + } else { + PrintF("Unrecognized argument.\n"); + } + } else if (strcmp(arg1, "enable") == 0) { + // Enable all/the specified breakpoint(s). + if (strcmp(arg2, "all") == 0) { + for (uint32_t i = 0; i < sim_->kNumOfWatchedStops; i++) { + sim_->EnableStop(i); + } + } else if (GetValue(arg2, &value)) { + sim_->EnableStop(value); + } else { + PrintF("Unrecognized argument.\n"); + } + } else if (strcmp(arg1, "disable") == 0) { + // Disable all/the specified breakpoint(s). + if (strcmp(arg2, "all") == 0) { + for (uint32_t i = 0; i < sim_->kNumOfWatchedStops; i++) { + sim_->DisableStop(i); + } + } else if (GetValue(arg2, &value)) { + sim_->DisableStop(value); + } else { + PrintF("Unrecognized argument.\n"); + } + } } else { - PrintF("Not at debugger stop."); + PrintF("Wrong usage. Use help command for more information.\n"); } } else if ((strcmp(cmd, "t") == 0) || strcmp(cmd, "trace") == 0) { ::v8::internal::FLAG_trace_sim = !::v8::internal::FLAG_trace_sim; @@ -455,11 +522,29 @@ void Debugger::Debug() { PrintF(" set a break point on the address\n"); PrintF("del\n"); PrintF(" delete the breakpoint\n"); - PrintF("unstop\n"); - PrintF(" ignore the stop instruction at the current location"); - PrintF(" from now on\n"); PrintF("trace (alias 't')\n"); PrintF(" toogle the tracing of all executed statements\n"); + PrintF("stop feature:\n"); + PrintF(" Description:\n"); + PrintF(" Stops are debug instructions inserted by\n"); + PrintF(" the Assembler::stop() function.\n"); + PrintF(" When hitting a stop, the Simulator will\n"); + PrintF(" stop and and give control to the Debugger.\n"); + PrintF(" The first %d stop codes are watched:\n", + Simulator::kNumOfWatchedStops); + PrintF(" - They can be enabled / disabled: the Simulator\n"); + PrintF(" will / won't stop when hitting them.\n"); + PrintF(" - The Simulator keeps track of how many times they \n"); + PrintF(" are met. (See the info command.) Going over a\n"); + PrintF(" disabled stop still increases its counter. \n"); + PrintF(" Commands:\n"); + PrintF(" stop info all/ : print infos about number \n"); + PrintF(" or all stop(s).\n"); + PrintF(" stop enable/disable all/ : enables / disables\n"); + PrintF(" all or number stop(s)\n"); + PrintF(" stop unstop\n"); + PrintF(" ignore the stop instruction at the current location\n"); + PrintF(" from now on\n"); } else { PrintF("Unknown command: %s\n", cmd); } @@ -643,9 +728,9 @@ Simulator::Simulator() { // the simulator. The external reference will be a function compiled for the // host architecture. We need to call that function instead of trying to // execute it with the simulator. We do that by redirecting the external -// reference to a swi (software-interrupt) instruction that is handled by +// reference to a svc (Supervisor Call) instruction that is handled by // the simulator. We write the original destination of the jump just at a known -// offset from the swi instruction so the simulator knows what to call. +// offset from the svc instruction so the simulator knows what to call. class Redirection { public: Redirection(void* external_function, bool fp_return) @@ -1434,8 +1519,8 @@ typedef double (*SimulatorRuntimeFPCall)(int32_t arg0, // Software interrupt instructions are used by the simulator to call into the // C-based V8 runtime. void Simulator::SoftwareInterrupt(Instr* instr) { - int swi = instr->SwiField(); - switch (swi) { + int svc = instr->SvcField(); + switch (svc) { case call_rt_redirected: { // Check if stack is aligned. Error if not aligned is reported below to // include information on the function called. @@ -1505,9 +1590,98 @@ void Simulator::SoftwareInterrupt(Instr* instr) { dbg.Debug(); break; } + // stop uses all codes greater than 1 << 23. default: { - UNREACHABLE(); - break; + if (svc >= (1 << 23)) { + uint32_t code = svc & kStopCodeMask; + if (isWatchedStop(code)) { + IncreaseStopCounter(code); + } + // Stop if it is enabled, otherwise go on jumping over the stop + // and the message address. + if (isEnabledStop(code)) { + Debugger dbg(this); + dbg.Stop(instr); + } else { + set_pc(get_pc() + 2 * Instr::kInstrSize); + } + } else { + // This is not a valid svc code. + UNREACHABLE(); + break; + } + } + } +} + + +// Stop helper functions. +bool Simulator::isStopInstruction(Instr* instr) { + return (instr->Bits(27, 24) == 0xF) && (instr->SvcField() >= stop); +} + + +bool Simulator::isWatchedStop(uint32_t code) { + ASSERT(code <= kMaxStopCode); + return code < kNumOfWatchedStops; +} + + +bool Simulator::isEnabledStop(uint32_t code) { + ASSERT(code <= kMaxStopCode); + // Unwatched stops are always enabled. + return !isWatchedStop(code) || + !(watched_stops[code].count & kStopDisabledBit); +} + + +void Simulator::EnableStop(uint32_t code) { + ASSERT(isWatchedStop(code)); + if (!isEnabledStop(code)) { + watched_stops[code].count &= ~kStopDisabledBit; + } +} + + +void Simulator::DisableStop(uint32_t code) { + ASSERT(isWatchedStop(code)); + if (isEnabledStop(code)) { + watched_stops[code].count |= kStopDisabledBit; + } +} + + +void Simulator::IncreaseStopCounter(uint32_t code) { + ASSERT(code <= kMaxStopCode); + ASSERT(isWatchedStop(code)); + if ((watched_stops[code].count & ~(1 << 31)) == 0x7fffffff) { + PrintF("Stop counter for code %i has overflowed.\n" + "Enabling this code and reseting the counter to 0.\n", code); + watched_stops[code].count = 0; + EnableStop(code); + } else { + watched_stops[code].count++; + } +} + + +// Print a stop status. +void Simulator::PrintStopInfo(uint32_t code) { + ASSERT(code <= kMaxStopCode); + if (!isWatchedStop(code)) { + PrintF("Stop not watched."); + } else { + const char* state = isEnabledStop(code) ? "Enabled" : "Disabled"; + int32_t count = watched_stops[code].count & ~kStopDisabledBit; + // Don't print the state of unused breakpoints. + if (count != 0) { + if (watched_stops[code].desc) { + PrintF("stop %i - 0x%x: \t%s, \tcounter = %i, \t%s\n", + code, code, state, count, watched_stops[code].desc); + } else { + PrintF("stop %i - 0x%x: \t%s, \tcounter = %i\n", + code, code, state, count); + } } } } @@ -2216,73 +2390,6 @@ void Simulator::DecodeType7(Instr* instr) { } -void Simulator::DecodeUnconditional(Instr* instr) { - if (instr->Bits(7, 4) == 0x0B && instr->Bits(27, 25) == 0 && instr->HasL()) { - // Load halfword instruction, either register or immediate offset. - int rd = instr->RdField(); - int rn = instr->RnField(); - int32_t rn_val = get_register(rn); - int32_t addr = 0; - int32_t offset; - if (instr->Bit(22) == 0) { - // Register offset. - int rm = instr->RmField(); - offset = get_register(rm); - } else { - // Immediate offset - offset = instr->Bits(3, 0) + (instr->Bits(11, 8) << 4); - } - switch (instr->PUField()) { - case 0: { - // Post index, negative. - ASSERT(!instr->HasW()); - addr = rn_val; - rn_val -= offset; - set_register(rn, rn_val); - break; - } - case 1: { - // Post index, positive. - ASSERT(!instr->HasW()); - addr = rn_val; - rn_val += offset; - set_register(rn, rn_val); - break; - } - case 2: { - // Pre index or offset, negative. - rn_val -= offset; - addr = rn_val; - if (instr->HasW()) { - set_register(rn, rn_val); - } - break; - } - case 3: { - // Pre index or offset, positive. - rn_val += offset; - addr = rn_val; - if (instr->HasW()) { - set_register(rn, rn_val); - } - break; - } - default: { - // The PU field is a 2-bit field. - UNREACHABLE(); - break; - } - } - // Not sign extending, so load as unsigned. - uint16_t halfword = ReadH(addr, instr); - set_register(rd, halfword); - } else { - Debugger dbg(this); - dbg.Stop(instr); - } -} - - // void Simulator::DecodeTypeVFP(Instr* instr) // The Following ARMv7 VFPv instructions are currently supported. // vmov :Sn = Rt @@ -2655,7 +2762,7 @@ void Simulator::InstructionDecode(Instr* instr) { PrintF(" 0x%08x %s\n", reinterpret_cast(instr), buffer.start()); } if (instr->ConditionField() == special_condition) { - DecodeUnconditional(instr); + UNIMPLEMENTED(); } else if (ConditionallyExecute(instr)) { switch (instr->TypeField()) { case 0: diff --git a/deps/v8/src/arm/simulator-arm.h b/deps/v8/src/arm/simulator-arm.h index e0658fc997..3e023489ee 100644 --- a/deps/v8/src/arm/simulator-arm.h +++ b/deps/v8/src/arm/simulator-arm.h @@ -226,6 +226,15 @@ class Simulator { void HandleRList(Instr* instr, bool load); void SoftwareInterrupt(Instr* instr); + // Stop helper functions. + inline bool isStopInstruction(Instr* instr); + inline bool isWatchedStop(uint32_t bkpt_code); + inline bool isEnabledStop(uint32_t bkpt_code); + inline void EnableStop(uint32_t bkpt_code); + inline void DisableStop(uint32_t bkpt_code); + inline void IncreaseStopCounter(uint32_t bkpt_code); + void PrintStopInfo(uint32_t code); + // Read and write memory. inline uint8_t ReadBU(int32_t addr); inline int8_t ReadB(int32_t addr); @@ -252,7 +261,6 @@ class Simulator { void DecodeType5(Instr* instr); void DecodeType6(Instr* instr); void DecodeType7(Instr* instr); - void DecodeUnconditional(Instr* instr); // Support for VFP. void DecodeTypeVFP(Instr* instr); @@ -317,6 +325,23 @@ class Simulator { // Registered breakpoints. Instr* break_pc_; instr_t break_instr_; + + // A stop is watched if its code is less than kNumOfWatchedStops. + // Only watched stops support enabling/disabling and the counter feature. + static const uint32_t kNumOfWatchedStops = 256; + + // Breakpoint is disabled if bit 31 is set. + static const uint32_t kStopDisabledBit = 1 << 31; + + // A stop is enabled, meaning the simulator will stop when meeting the + // instruction, if bit 31 of watched_stops[code].count is unset. + // The value watched_stops[code].count & ~(1 << 31) indicates how many times + // the breakpoint was hit or gone through. + struct StopCoundAndDesc { + uint32_t count; + char* desc; + }; + StopCoundAndDesc watched_stops[kNumOfWatchedStops]; }; } } // namespace assembler::arm diff --git a/deps/v8/src/arm/stub-cache-arm.cc b/deps/v8/src/arm/stub-cache-arm.cc index fbad6698bd..5e29c2e485 100644 --- a/deps/v8/src/arm/stub-cache-arm.cc +++ b/deps/v8/src/arm/stub-cache-arm.cc @@ -43,43 +43,49 @@ static void ProbeTable(MacroAssembler* masm, Code::Flags flags, StubCache::Table table, Register name, - Register offset) { + Register offset, + Register scratch, + Register scratch2) { ExternalReference key_offset(SCTableReference::keyReference(table)); ExternalReference value_offset(SCTableReference::valueReference(table)); - Label miss; + uint32_t key_off_addr = reinterpret_cast(key_offset.address()); + uint32_t value_off_addr = reinterpret_cast(value_offset.address()); + + // Check the relative positions of the address fields. + ASSERT(value_off_addr > key_off_addr); + ASSERT((value_off_addr - key_off_addr) % 4 == 0); + ASSERT((value_off_addr - key_off_addr) < (256 * 4)); - // Save the offset on the stack. - __ push(offset); + Label miss; + Register offsets_base_addr = scratch; // Check that the key in the entry matches the name. - __ mov(ip, Operand(key_offset)); - __ ldr(ip, MemOperand(ip, offset, LSL, 1)); + __ mov(offsets_base_addr, Operand(key_offset)); + __ ldr(ip, MemOperand(offsets_base_addr, offset, LSL, 1)); __ cmp(name, ip); __ b(ne, &miss); // Get the code entry from the cache. - __ mov(ip, Operand(value_offset)); - __ ldr(offset, MemOperand(ip, offset, LSL, 1)); + __ add(offsets_base_addr, offsets_base_addr, + Operand(value_off_addr - key_off_addr)); + __ ldr(scratch2, MemOperand(offsets_base_addr, offset, LSL, 1)); // Check that the flags match what we're looking for. - __ ldr(offset, FieldMemOperand(offset, Code::kFlagsOffset)); - __ and_(offset, offset, Operand(~Code::kFlagsNotUsedInLookup)); - __ cmp(offset, Operand(flags)); + __ ldr(scratch2, FieldMemOperand(scratch2, Code::kFlagsOffset)); + __ bic(scratch2, scratch2, Operand(Code::kFlagsNotUsedInLookup)); + __ cmp(scratch2, Operand(flags)); __ b(ne, &miss); - // Restore offset and re-load code entry from cache. - __ pop(offset); - __ mov(ip, Operand(value_offset)); - __ ldr(offset, MemOperand(ip, offset, LSL, 1)); + // Re-load code entry from cache. + __ ldr(offset, MemOperand(offsets_base_addr, offset, LSL, 1)); // Jump to the first instruction in the code stub. __ add(offset, offset, Operand(Code::kHeaderSize - kHeapObjectTag)); __ Jump(offset); - // Miss: Restore offset and fall through. + // Miss: fall through. __ bind(&miss); - __ pop(offset); } @@ -201,7 +207,8 @@ void StubCache::GenerateProbe(MacroAssembler* masm, Register receiver, Register name, Register scratch, - Register extra) { + Register extra, + Register extra2) { Label miss; // Make sure that code is valid. The shifting code relies on the @@ -214,6 +221,18 @@ void StubCache::GenerateProbe(MacroAssembler* masm, // Make sure that there are no register conflicts. ASSERT(!scratch.is(receiver)); ASSERT(!scratch.is(name)); + ASSERT(!extra.is(receiver)); + ASSERT(!extra.is(name)); + ASSERT(!extra.is(scratch)); + ASSERT(!extra2.is(receiver)); + ASSERT(!extra2.is(name)); + ASSERT(!extra2.is(scratch)); + ASSERT(!extra2.is(extra)); + + // Check scratch, extra and extra2 registers are valid. + ASSERT(!scratch.is(no_reg)); + ASSERT(!extra.is(no_reg)); + ASSERT(!extra2.is(no_reg)); // Check that the receiver isn't a smi. __ tst(receiver, Operand(kSmiTagMask)); @@ -229,7 +248,7 @@ void StubCache::GenerateProbe(MacroAssembler* masm, Operand((kPrimaryTableSize - 1) << kHeapObjectTagSize)); // Probe the primary table. - ProbeTable(masm, flags, kPrimary, name, scratch); + ProbeTable(masm, flags, kPrimary, name, scratch, extra, extra2); // Primary miss: Compute hash for secondary probe. __ sub(scratch, scratch, Operand(name)); @@ -239,7 +258,7 @@ void StubCache::GenerateProbe(MacroAssembler* masm, Operand((kSecondaryTableSize - 1) << kHeapObjectTagSize)); // Probe the secondary table. - ProbeTable(masm, flags, kSecondary, name, scratch); + ProbeTable(masm, flags, kSecondary, name, scratch, extra, extra2); // Cache miss: Fall-through and let caller handle the miss by // entering the runtime system. diff --git a/deps/v8/src/ast.cc b/deps/v8/src/ast.cc index 92f14961b8..bb445c4d24 100644 --- a/deps/v8/src/ast.cc +++ b/deps/v8/src/ast.cc @@ -140,6 +140,7 @@ bool FunctionLiteral::AllowsLazyCompilation() { ObjectLiteral::Property::Property(Literal* key, Expression* value) { + emit_store_ = true; key_ = key; value_ = value; Object* k = *key->handle(); @@ -156,6 +157,7 @@ ObjectLiteral::Property::Property(Literal* key, Expression* value) { ObjectLiteral::Property::Property(bool is_getter, FunctionLiteral* value) { + emit_store_ = true; key_ = new Literal(value->name()); value_ = value; kind_ = is_getter ? GETTER : SETTER; @@ -169,6 +171,78 @@ bool ObjectLiteral::Property::IsCompileTimeValue() { } +void ObjectLiteral::Property::set_emit_store(bool emit_store) { + emit_store_ = emit_store; +} + + +bool ObjectLiteral::Property::emit_store() { + return emit_store_; +} + + +bool IsEqualString(void* first, void* second) { + Handle h1(reinterpret_cast(first)); + Handle h2(reinterpret_cast(second)); + return (*h1)->Equals(*h2); +} + +bool IsEqualSmi(void* first, void* second) { + Handle h1(reinterpret_cast(first)); + Handle h2(reinterpret_cast(second)); + return (*h1)->value() == (*h2)->value(); +} + +void ObjectLiteral::CalculateEmitStore() { + HashMap properties(&IsEqualString); + HashMap elements(&IsEqualSmi); + for (int i = this->properties()->length() - 1; i >= 0; i--) { + ObjectLiteral::Property* property = this->properties()->at(i); + Literal* literal = property->key(); + Handle handle = literal->handle(); + + if (handle->IsNull()) { + continue; + } + + uint32_t hash; + HashMap* table; + void* key; + uint32_t index; + if (handle->IsSymbol()) { + Handle name(String::cast(*handle)); + ASSERT(!name->AsArrayIndex(&index)); + key = name.location(); + hash = name->Hash(); + table = &properties; + } else if (handle->ToArrayIndex(&index)) { + key = handle.location(); + hash = index; + table = &elements; + } else { + ASSERT(handle->IsNumber()); + double num = handle->Number(); + char arr[100]; + Vector buffer(arr, ARRAY_SIZE(arr)); + const char* str = DoubleToCString(num, buffer); + Handle name = Factory::NewStringFromAscii(CStrVector(str)); + key = name.location(); + hash = name->Hash(); + table = &properties; + } + // If the key of a computed property is in the table, do not emit + // a store for the property later. + if (property->kind() == ObjectLiteral::Property::COMPUTED) { + if (table->Lookup(literal, hash, false) != NULL) { + property->set_emit_store(false); + } + } + // Add key to the table. + table->Lookup(literal, hash, true); + } +} + + void TargetCollector::AddTarget(BreakTarget* target) { // Add the label to the collector, but discard duplicates. int length = targets_->length(); diff --git a/deps/v8/src/ast.h b/deps/v8/src/ast.h index a01e48daeb..04c2977570 100644 --- a/deps/v8/src/ast.h +++ b/deps/v8/src/ast.h @@ -832,10 +832,14 @@ class ObjectLiteral: public MaterializedLiteral { bool IsCompileTimeValue(); + void set_emit_store(bool emit_store); + bool emit_store(); + private: Literal* key_; Expression* value_; Kind kind_; + bool emit_store_; }; ObjectLiteral(Handle constant_properties, @@ -858,6 +862,12 @@ class ObjectLiteral: public MaterializedLiteral { bool fast_elements() const { return fast_elements_; } + + // Mark all computed expressions that are bound to a key that + // is shadowed by a later occurrence of the same key. For the + // marked expressions, no store code is emitted. + void CalculateEmitStore(); + private: Handle constant_properties_; ZoneList* properties_; diff --git a/deps/v8/src/builtins.cc b/deps/v8/src/builtins.cc index 52d5530cec..aede302035 100644 --- a/deps/v8/src/builtins.cc +++ b/deps/v8/src/builtins.cc @@ -1014,20 +1014,18 @@ MUST_USE_RESULT static MaybeObject* HandleApiCallHelper( Object* data_obj = call_data->data(); Object* result; - Handle data_handle(data_obj); - v8::Local data = v8::Utils::ToLocal(data_handle); - ASSERT(raw_holder->IsJSObject()); - v8::Local callee = v8::Utils::ToLocal(function); - Handle holder_handle(JSObject::cast(raw_holder)); - v8::Local holder = v8::Utils::ToLocal(holder_handle); LOG(ApiObjectAccess("call", JSObject::cast(*args.receiver()))); + ASSERT(raw_holder->IsJSObject()); + + CustomArguments custom; + v8::ImplementationUtilities::PrepareArgumentsData(custom.end(), + data_obj, *function, raw_holder); + v8::Arguments new_args = v8::ImplementationUtilities::NewArguments( - data, - holder, - callee, - is_construct, - reinterpret_cast(&args[0] - 1), - args.length() - 1); + custom.end(), + &args[0] - 1, + args.length() - 1, + is_construct); v8::Handle value; { @@ -1089,26 +1087,22 @@ BUILTIN(FastHandleApiCall) { Handle function = args.at(args_length); Object* callback_obj = args[args_length + 1]; - Handle data_handle = args.at(args_length + 2); + Handle data = args.at(args_length + 2); Handle checked_holder = args.at(args_length + 3); #ifdef DEBUG VerifyTypeCheck(checked_holder, function); #endif - v8::Local holder = v8::Utils::ToLocal(checked_holder); - v8::Local callee = v8::Utils::ToLocal(function); - v8::InvocationCallback callback = - v8::ToCData(callback_obj); - v8::Local data = v8::Utils::ToLocal(data_handle); + CustomArguments custom; + v8::ImplementationUtilities::PrepareArgumentsData(custom.end(), + *data, *function, *checked_holder); v8::Arguments new_args = v8::ImplementationUtilities::NewArguments( - data, - holder, - callee, - is_construct, - reinterpret_cast(&args[0] - 1), - args_length - 1); + custom.end(), + &args[0] - 1, + args_length - 1, + is_construct); HandleScope scope; Object* result; @@ -1119,6 +1113,9 @@ BUILTIN(FastHandleApiCall) { #ifdef ENABLE_LOGGING_AND_PROFILING state.set_external_callback(v8::ToCData
(callback_obj)); #endif + v8::InvocationCallback callback = + v8::ToCData(callback_obj); + value = callback(new_args); } if (value.IsEmpty()) { @@ -1161,23 +1158,20 @@ MUST_USE_RESULT static MaybeObject* HandleApiCallAsFunctionOrConstructor( v8::ToCData(callback_obj); // Get the data for the call and perform the callback. - Object* data_obj = call_data->data(); Object* result; - { HandleScope scope; - v8::Local self = - v8::Utils::ToLocal(Handle::cast(args.receiver())); - Handle data_handle(data_obj); - v8::Local data = v8::Utils::ToLocal(data_handle); - Handle callee_handle(constructor); - v8::Local callee = v8::Utils::ToLocal(callee_handle); - LOG(ApiObjectAccess("call non-function", JSObject::cast(*args.receiver()))); + { + HandleScope scope; + + LOG(ApiObjectAccess("call non-function", obj)); + + CustomArguments custom; + v8::ImplementationUtilities::PrepareArgumentsData(custom.end(), + call_data->data(), constructor, obj); v8::Arguments new_args = v8::ImplementationUtilities::NewArguments( - data, - self, - callee, - is_construct_call, - reinterpret_cast(&args[0] - 1), - args.length() - 1); + custom.end(), + &args[0] - 1, + args.length() - 1, + is_construct_call); v8::Handle value; { // Leaving JavaScript. diff --git a/deps/v8/src/compiler.cc b/deps/v8/src/compiler.cc index 6cc09713d6..6f02960dda 100755 --- a/deps/v8/src/compiler.cc +++ b/deps/v8/src/compiler.cc @@ -152,10 +152,8 @@ static Handle MakeFunctionInfo(CompilationInfo* info) { script->set_context_data((*i::Top::global_context())->data()); #ifdef ENABLE_DEBUGGER_SUPPORT - if (info->is_eval() || info->is_json()) { - Script::CompilationType compilation_type = info->is_json() - ? Script::COMPILATION_TYPE_JSON - : Script::COMPILATION_TYPE_EVAL; + if (info->is_eval()) { + Script::CompilationType compilation_type = Script::COMPILATION_TYPE_EVAL; script->set_compilation_type(Smi::FromInt(compilation_type)); // For eval scripts add information on the function from which eval was // called. @@ -178,7 +176,7 @@ static Handle MakeFunctionInfo(CompilationInfo* info) { // Only allow non-global compiles for eval. ASSERT(info->is_eval() || info->is_global()); - if (!Parser::Parse(info)) return Handle::null(); + if (!ParserApi::Parse(info)) return Handle::null(); // Measure how long it takes to do the compilation; only take the // rest of the function into account to avoid overlap with the @@ -283,7 +281,7 @@ Handle Compiler::Compile(Handle source, if (pre_data == NULL && FLAG_lazy && source_length >= FLAG_min_preparse_length) { - pre_data = Parser::PartialPreParse(source, NULL, extension); + pre_data = ParserApi::PartialPreParse(source, NULL, extension); } // Create a script object describing the script to be compiled. @@ -323,13 +321,7 @@ Handle Compiler::Compile(Handle source, Handle Compiler::CompileEval(Handle source, Handle context, - bool is_global, - ValidationState validate) { - // Note that if validation is required then no path through this function - // is allowed to return a value without validating that the input is legal - // json. - bool is_json = (validate == VALIDATE_JSON); - + bool is_global) { int source_length = source->length(); Counters::total_eval_size.Increment(source_length); Counters::total_compile_size.Increment(source_length); @@ -338,13 +330,9 @@ Handle Compiler::CompileEval(Handle source, VMState state(COMPILER); // Do a lookup in the compilation cache; if the entry is not there, invoke - // the compiler and add the result to the cache. If we're evaluating json - // we bypass the cache since we can't be sure a potential value in the - // cache has been validated. + // the compiler and add the result to the cache. Handle result; - if (!is_json) { - result = CompilationCache::LookupEval(source, context, is_global); - } + result = CompilationCache::LookupEval(source, context, is_global); if (result.is_null()) { // Create a script object describing the script to be compiled. @@ -352,12 +340,9 @@ Handle Compiler::CompileEval(Handle source, CompilationInfo info(script); info.MarkAsEval(); if (is_global) info.MarkAsGlobal(); - if (is_json) info.MarkAsJson(); info.SetCallingContext(context); result = MakeFunctionInfo(&info); - if (!result.is_null() && !is_json) { - // For json it's unlikely that we'll ever see exactly the same string - // again so we don't use the compilation cache. + if (!result.is_null()) { CompilationCache::PutEval(source, context, is_global, result); } } @@ -379,7 +364,7 @@ bool Compiler::CompileLazy(CompilationInfo* info) { Counters::total_compile_size.Increment(compiled_size); // Generate the AST for the lazily compiled function. - if (Parser::Parse(info)) { + if (ParserApi::Parse(info)) { // Measure how long it takes to do the lazy compilation; only take the // rest of the function into account to avoid overlap with the lazy // parsing statistics. diff --git a/deps/v8/src/compiler.h b/deps/v8/src/compiler.h index d6f4e69d52..20868e5488 100644 --- a/deps/v8/src/compiler.h +++ b/deps/v8/src/compiler.h @@ -49,7 +49,6 @@ class CompilationInfo BASE_EMBEDDED { bool is_lazy() const { return (flags_ & IsLazy::mask()) != 0; } bool is_eval() const { return (flags_ & IsEval::mask()) != 0; } bool is_global() const { return (flags_ & IsGlobal::mask()) != 0; } - bool is_json() const { return (flags_ & IsJson::mask()) != 0; } bool is_in_loop() const { return (flags_ & IsInLoop::mask()) != 0; } FunctionLiteral* function() const { return function_; } Scope* scope() const { return scope_; } @@ -69,10 +68,6 @@ class CompilationInfo BASE_EMBEDDED { ASSERT(!is_lazy()); flags_ |= IsGlobal::encode(true); } - void MarkAsJson() { - ASSERT(!is_lazy()); - flags_ |= IsJson::encode(true); - } void MarkAsInLoop() { ASSERT(is_lazy()); flags_ |= IsInLoop::encode(true); @@ -108,16 +103,15 @@ class CompilationInfo BASE_EMBEDDED { // Flags that can be set for eager compilation. class IsEval: public BitField {}; class IsGlobal: public BitField {}; - class IsJson: public BitField {}; // Flags that can be set for lazy compilation. - class IsInLoop: public BitField {}; + class IsInLoop: public BitField {}; unsigned flags_; // Fields filled in by the compilation pipeline. // AST filled in by the parser. FunctionLiteral* function_; - // The scope of the function literal as a convenience. Set to indidicate + // The scope of the function literal as a convenience. Set to indicate // that scopes have been analyzed. Scope* scope_; // The compiled code. @@ -153,8 +147,6 @@ class CompilationInfo BASE_EMBEDDED { class Compiler : public AllStatic { public: - enum ValidationState { DONT_VALIDATE_JSON, VALIDATE_JSON }; - // All routines return a JSFunction. // If an error occurs an exception is raised and // the return handle contains NULL. @@ -172,8 +164,7 @@ class Compiler : public AllStatic { // Compile a String source within a context for Eval. static Handle CompileEval(Handle source, Handle context, - bool is_global, - ValidationState validation); + bool is_global); // Compile from function info (used for lazy compilation). Returns true on // success and false if the compilation resulted in a stack overflow. diff --git a/deps/v8/src/debug-debugger.js b/deps/v8/src/debug-debugger.js index a0c6808102..0eab8d1b83 100644 --- a/deps/v8/src/debug-debugger.js +++ b/deps/v8/src/debug-debugger.js @@ -1301,7 +1301,7 @@ DebugCommandProcessor.prototype.processDebugJSONRequest = function(json_request) try { try { // Convert the JSON string to an object. - request = %CompileString('(' + json_request + ')', false)(); + request = %CompileString('(' + json_request + ')')(); // Create an initial response. response = this.createResponse(request); diff --git a/deps/v8/src/debug.cc b/deps/v8/src/debug.cc index 5c6ddbe355..24f0409861 100644 --- a/deps/v8/src/debug.cc +++ b/deps/v8/src/debug.cc @@ -1464,8 +1464,7 @@ bool Debug::IsSourceBreakStub(Code* code) { // location. bool Debug::IsBreakStub(Code* code) { CodeStub::Major major_key = CodeStub::GetMajorKey(code); - return major_key == CodeStub::CallFunction || - major_key == CodeStub::StackCheck; + return major_key == CodeStub::CallFunction; } @@ -1503,8 +1502,7 @@ Handle Debug::FindDebugBreak(Handle code, RelocInfo::Mode mode) { return result; } if (code->kind() == Code::STUB) { - ASSERT(code->major_key() == CodeStub::CallFunction || - code->major_key() == CodeStub::StackCheck); + ASSERT(code->major_key() == CodeStub::CallFunction); Handle result = Handle(Builtins::builtin(Builtins::StubNoRegisters_DebugBreak)); return result; diff --git a/deps/v8/src/execution.cc b/deps/v8/src/execution.cc index 3bbac0fa07..885bf63cf1 100644 --- a/deps/v8/src/execution.cc +++ b/deps/v8/src/execution.cc @@ -797,6 +797,7 @@ v8::Handle ExternalizeStringExtension::Externalize( if (result && !string->IsSymbol()) { i::ExternalStringTable::AddString(*string); } + if (!result) delete resource; } else { uc16* data = new uc16[string->length()]; String::WriteToFlat(*string, data, 0, string->length()); @@ -806,6 +807,7 @@ v8::Handle ExternalizeStringExtension::Externalize( if (result && !string->IsSymbol()) { i::ExternalStringTable::AddString(*string); } + if (!result) delete resource; } if (!result) { return v8::ThrowException(v8::String::New("externalizeString() failed.")); diff --git a/deps/v8/src/flag-definitions.h b/deps/v8/src/flag-definitions.h index 2474c62bc3..54501ec95d 100644 --- a/deps/v8/src/flag-definitions.h +++ b/deps/v8/src/flag-definitions.h @@ -140,6 +140,9 @@ DEFINE_bool(stack_trace_on_abort, true, // codegen-ia32.cc / codegen-arm.cc DEFINE_bool(trace, false, "trace function calls") DEFINE_bool(defer_negation, true, "defer negation operation") +DEFINE_bool(mask_constants_with_cookie, + true, + "use random jit cookie to mask large constants") // codegen.cc DEFINE_bool(lazy, true, "use lazy compilation") diff --git a/deps/v8/src/heap.cc b/deps/v8/src/heap.cc index fc90866552..b037efd804 100644 --- a/deps/v8/src/heap.cc +++ b/deps/v8/src/heap.cc @@ -581,25 +581,22 @@ void Heap::EnsureFromSpaceIsCommitted() { } -class ClearThreadJSFunctionResultCachesVisitor: public ThreadVisitor { - virtual void VisitThread(ThreadLocalTop* top) { - Context* context = top->context_; - if (context == NULL) return; +void Heap::ClearJSFunctionResultCaches() { + if (Bootstrapper::IsActive()) return; + Object* context = global_contexts_list_; + while (!context->IsUndefined()) { + // Get the caches for this context: FixedArray* caches = - context->global()->global_context()->jsfunction_result_caches(); + Context::cast(context)->jsfunction_result_caches(); + // Clear the caches: int length = caches->length(); for (int i = 0; i < length; i++) { JSFunctionResultCache::cast(caches->get(i))->Clear(); } + // Get the next context: + context = Context::cast(context)->get(Context::NEXT_CONTEXT_LINK); } -}; - - -void Heap::ClearJSFunctionResultCaches() { - if (Bootstrapper::IsActive()) return; - ClearThreadJSFunctionResultCachesVisitor visitor; - ThreadManager::IterateArchivedThreads(&visitor); } diff --git a/deps/v8/src/ia32/codegen-ia32.cc b/deps/v8/src/ia32/codegen-ia32.cc index f2ac7f7022..6d23dd7df9 100644 --- a/deps/v8/src/ia32/codegen-ia32.cc +++ b/deps/v8/src/ia32/codegen-ia32.cc @@ -153,7 +153,8 @@ CodeGenerator::CodeGenerator(MacroAssembler* masm) in_safe_int32_mode_(false), safe_int32_mode_enabled_(true), function_return_is_shadowed_(false), - in_spilled_code_(false) { + in_spilled_code_(false), + jit_cookie_((FLAG_mask_constants_with_cookie) ? V8::Random() : 0) { } @@ -5363,16 +5364,16 @@ void CodeGenerator::VisitLiteral(Literal* node) { void CodeGenerator::PushUnsafeSmi(Handle value) { ASSERT(value->IsSmi()); int bits = reinterpret_cast(*value); - __ push(Immediate(bits & 0x0000FFFF)); - __ or_(Operand(esp, 0), Immediate(bits & 0xFFFF0000)); + __ push(Immediate(bits ^ jit_cookie_)); + __ xor_(Operand(esp, 0), Immediate(jit_cookie_)); } void CodeGenerator::StoreUnsafeSmiToLocal(int offset, Handle value) { ASSERT(value->IsSmi()); int bits = reinterpret_cast(*value); - __ mov(Operand(ebp, offset), Immediate(bits & 0x0000FFFF)); - __ or_(Operand(ebp, offset), Immediate(bits & 0xFFFF0000)); + __ mov(Operand(ebp, offset), Immediate(bits ^ jit_cookie_)); + __ xor_(Operand(ebp, offset), Immediate(jit_cookie_)); } @@ -5380,8 +5381,8 @@ void CodeGenerator::MoveUnsafeSmi(Register target, Handle value) { ASSERT(target.is_valid()); ASSERT(value->IsSmi()); int bits = reinterpret_cast(*value); - __ Set(target, Immediate(bits & 0x0000FFFF)); - __ or_(target, bits & 0xFFFF0000); + __ Set(target, Immediate(bits ^ jit_cookie_)); + __ xor_(target, jit_cookie_); } @@ -5559,6 +5560,11 @@ void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) { } frame_->Push(&clone); + // Mark all computed expressions that are bound to a key that + // is shadowed by a later occurrence of the same key. For the + // marked expressions, no store code is emitted. + node->CalculateEmitStore(); + for (int i = 0; i < node->properties()->length(); i++) { ObjectLiteral::Property* property = node->properties()->at(i); switch (property->kind()) { @@ -5573,24 +5579,32 @@ void CodeGenerator::VisitObjectLiteral(ObjectLiteral* node) { // Duplicate the object as the IC receiver. frame_->Dup(); Load(property->value()); - Result ignored = - frame_->CallStoreIC(Handle::cast(key), false); - // A test eax instruction following the store IC call would - // indicate the presence of an inlined version of the - // store. Add a nop to indicate that there is no such - // inlined version. - __ nop(); + if (property->emit_store()) { + Result ignored = + frame_->CallStoreIC(Handle::cast(key), false); + // A test eax instruction following the store IC call would + // indicate the presence of an inlined version of the + // store. Add a nop to indicate that there is no such + // inlined version. + __ nop(); + } else { + frame_->Drop(2); + } break; } // Fall through } case ObjectLiteral::Property::PROTOTYPE: { - // Duplicate the object as an argument to the runtime call. - frame_->Dup(); - Load(property->key()); - Load(property->value()); - Result ignored = frame_->CallRuntime(Runtime::kSetProperty, 3); - // Ignore the result. + // Duplicate the object as an argument to the runtime call. + frame_->Dup(); + Load(property->key()); + Load(property->value()); + if (property->emit_store()) { + // Ignore the result. + Result ignored = frame_->CallRuntime(Runtime::kSetProperty, 3); + } else { + frame_->Drop(3); + } break; } case ObjectLiteral::Property::SETTER: { diff --git a/deps/v8/src/ia32/codegen-ia32.h b/deps/v8/src/ia32/codegen-ia32.h index b0724092f8..4594b19ddd 100644 --- a/deps/v8/src/ia32/codegen-ia32.h +++ b/deps/v8/src/ia32/codegen-ia32.h @@ -785,6 +785,11 @@ class CodeGenerator: public AstVisitor { // in a spilled state. bool in_spilled_code_; + // A cookie that is used for JIT IMM32 Encoding. Initialized to a + // random number when the command-line + // FLAG_mask_constants_with_cookie is true, zero otherwise. + int jit_cookie_; + friend class VirtualFrame; friend class JumpTarget; friend class Reference; diff --git a/deps/v8/src/ia32/full-codegen-ia32.cc b/deps/v8/src/ia32/full-codegen-ia32.cc index 150df9953b..ee4e6458ae 100644 --- a/deps/v8/src/ia32/full-codegen-ia32.cc +++ b/deps/v8/src/ia32/full-codegen-ia32.cc @@ -1202,6 +1202,11 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { // result_saved is false the result is in eax. bool result_saved = false; + // Mark all computed expressions that are bound to a key that + // is shadowed by a later occurrence of the same key. For the + // marked expressions, no store code is emitted. + expr->CalculateEmitStore(); + for (int i = 0; i < expr->properties()->length(); i++) { ObjectLiteral::Property* property = expr->properties()->at(i); if (property->IsCompileTimeValue()) continue; @@ -1221,8 +1226,10 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { VisitForAccumulatorValue(value); __ mov(ecx, Immediate(key->handle())); __ mov(edx, Operand(esp, 0)); - Handle ic(Builtins::builtin(Builtins::StoreIC_Initialize)); - EmitCallIC(ic, RelocInfo::CODE_TARGET); + if (property->emit_store()) { + Handle ic(Builtins::builtin(Builtins::StoreIC_Initialize)); + EmitCallIC(ic, RelocInfo::CODE_TARGET); + } break; } // Fall through. @@ -1230,7 +1237,11 @@ void FullCodeGenerator::VisitObjectLiteral(ObjectLiteral* expr) { __ push(Operand(esp, 0)); // Duplicate receiver. VisitForStackValue(key); VisitForStackValue(value); - __ CallRuntime(Runtime::kSetProperty, 3); + if (property->emit_store()) { + __ CallRuntime(Runtime::kSetProperty, 3); + } else { + __ Drop(3); + } break; case ObjectLiteral::Property::SETTER: case ObjectLiteral::Property::GETTER: diff --git a/deps/v8/src/ia32/stub-cache-ia32.cc b/deps/v8/src/ia32/stub-cache-ia32.cc index 90dabed0e5..e387088359 100644 --- a/deps/v8/src/ia32/stub-cache-ia32.cc +++ b/deps/v8/src/ia32/stub-cache-ia32.cc @@ -206,8 +206,10 @@ void StubCache::GenerateProbe(MacroAssembler* masm, Register receiver, Register name, Register scratch, - Register extra) { + Register extra, + Register extra2) { Label miss; + USE(extra2); // The register extra2 is not used on the ia32 platform. // Make sure that code is valid. The shifting code relies on the // entry size being 8. @@ -223,6 +225,10 @@ void StubCache::GenerateProbe(MacroAssembler* masm, ASSERT(!extra.is(name)); ASSERT(!extra.is(scratch)); + // Check scratch and extra registers are valid, and extra2 is unused. + ASSERT(!scratch.is(no_reg)); + ASSERT(extra2.is(no_reg)); + // Check that the receiver isn't a smi. __ test(receiver, Immediate(kSmiTagMask)); __ j(zero, &miss, not_taken); diff --git a/deps/v8/src/json.js b/deps/v8/src/json.js index a39d7c4a97..5993100f53 100644 --- a/deps/v8/src/json.js +++ b/deps/v8/src/json.js @@ -29,8 +29,7 @@ var $JSON = global.JSON; function ParseJSONUnfiltered(text) { var s = $String(text); - var f = %CompileString(s, true); - return f(); + return %ParseJson(s); } function Revive(holder, name, reviver) { diff --git a/deps/v8/src/jsregexp.cc b/deps/v8/src/jsregexp.cc index 3c5ddfbeb4..8cd13bc416 100644 --- a/deps/v8/src/jsregexp.cc +++ b/deps/v8/src/jsregexp.cc @@ -125,7 +125,8 @@ Handle RegExpImpl::Compile(Handle re, PostponeInterruptsScope postpone; RegExpCompileData parse_result; FlatStringReader reader(pattern); - if (!Parser::ParseRegExp(&reader, flags.is_multiline(), &parse_result)) { + if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), + &parse_result)) { // Throw an exception if we fail to parse the pattern. ThrowRegExpException(re, pattern, @@ -267,7 +268,8 @@ bool RegExpImpl::CompileIrregexp(Handle re, bool is_ascii) { RegExpCompileData compile_data; FlatStringReader reader(pattern); - if (!Parser::ParseRegExp(&reader, flags.is_multiline(), &compile_data)) { + if (!RegExpParser::ParseRegExp(&reader, flags.is_multiline(), + &compile_data)) { // Throw an exception if we fail to parse the pattern. // THIS SHOULD NOT HAPPEN. We already pre-parsed it successfully once. ThrowRegExpException(re, diff --git a/deps/v8/src/liveedit.cc b/deps/v8/src/liveedit.cc index 49f221a466..642b3e6a04 100644 --- a/deps/v8/src/liveedit.cc +++ b/deps/v8/src/liveedit.cc @@ -404,7 +404,7 @@ static void CompileScriptForTracker(Handle