| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 7386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7397 RUNTIME_GET_ISOLATE; | 7397 RUNTIME_GET_ISOLATE; |
| 7398 // Allocate a block of memory in NewSpace (filled with a filler). | 7398 // Allocate a block of memory in NewSpace (filled with a filler). |
| 7399 // Use as fallback for allocation in generated code when NewSpace | 7399 // Use as fallback for allocation in generated code when NewSpace |
| 7400 // is full. | 7400 // is full. |
| 7401 ASSERT(args.length() == 1); | 7401 ASSERT(args.length() == 1); |
| 7402 CONVERT_ARG_CHECKED(Smi, size_smi, 0); | 7402 CONVERT_ARG_CHECKED(Smi, size_smi, 0); |
| 7403 int size = size_smi->value(); | 7403 int size = size_smi->value(); |
| 7404 RUNTIME_ASSERT(IsAligned(size, kPointerSize)); | 7404 RUNTIME_ASSERT(IsAligned(size, kPointerSize)); |
| 7405 RUNTIME_ASSERT(size > 0); | 7405 RUNTIME_ASSERT(size > 0); |
| 7406 Heap* heap = isolate->heap(); | 7406 Heap* heap = isolate->heap(); |
| 7407 static const int kMinFreeNewSpaceAfterGC = heap->InitialSemiSpaceSize() * 3/4; | 7407 const int kMinFreeNewSpaceAfterGC = heap->InitialSemiSpaceSize() * 3/4; |
| 7408 RUNTIME_ASSERT(size <= kMinFreeNewSpaceAfterGC); | 7408 RUNTIME_ASSERT(size <= kMinFreeNewSpaceAfterGC); |
| 7409 Object* allocation = heap->new_space()->AllocateRaw(size); | 7409 Object* allocation = heap->new_space()->AllocateRaw(size); |
| 7410 if (!allocation->IsFailure()) { | 7410 if (!allocation->IsFailure()) { |
| 7411 heap->CreateFillerObjectAt(HeapObject::cast(allocation)->address(), size); | 7411 heap->CreateFillerObjectAt(HeapObject::cast(allocation)->address(), size); |
| 7412 } | 7412 } |
| 7413 return allocation; | 7413 return allocation; |
| 7414 } | 7414 } |
| 7415 | 7415 |
| 7416 | 7416 |
| 7417 // Push an array unto an array of arrays if it is not already in the | 7417 // Push an array unto an array of arrays if it is not already in the |
| (...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8401 SaveContext* save = isolate->save_context(); | 8401 SaveContext* save = isolate->save_context(); |
| 8402 while (save != NULL && !save->below(it.frame())) { | 8402 while (save != NULL && !save->below(it.frame())) { |
| 8403 save = save->prev(); | 8403 save = save->prev(); |
| 8404 } | 8404 } |
| 8405 ASSERT(save != NULL); | 8405 ASSERT(save != NULL); |
| 8406 | 8406 |
| 8407 // Get the frame id. | 8407 // Get the frame id. |
| 8408 Handle<Object> frame_id(WrapFrameId(it.frame()->id()), isolate); | 8408 Handle<Object> frame_id(WrapFrameId(it.frame()->id()), isolate); |
| 8409 | 8409 |
| 8410 // Find source position. | 8410 // Find source position. |
| 8411 int position = it.frame()->code()->SourcePosition(it.frame()->pc()); | 8411 int position = |
| 8412 it.frame()->LookupCode(isolate)->SourcePosition(it.frame()->pc()); |
| 8412 | 8413 |
| 8413 // Check for constructor frame. | 8414 // Check for constructor frame. |
| 8414 bool constructor = it.frame()->IsConstructor(); | 8415 bool constructor = it.frame()->IsConstructor(); |
| 8415 | 8416 |
| 8416 // Get scope info and read from it for local variable information. | 8417 // Get scope info and read from it for local variable information. |
| 8417 Handle<JSFunction> function(JSFunction::cast(it.frame()->function())); | 8418 Handle<JSFunction> function(JSFunction::cast(it.frame()->function())); |
| 8418 Handle<SerializedScopeInfo> scope_info(function->shared()->scope_info()); | 8419 Handle<SerializedScopeInfo> scope_info(function->shared()->scope_info()); |
| 8419 ScopeInfo<> info(*scope_info); | 8420 ScopeInfo<> info(*scope_info); |
| 8420 | 8421 |
| 8421 // Get the context. | 8422 // Get the context. |
| (...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9474 AssertNoAllocation no_gc; | 9475 AssertNoAllocation no_gc; |
| 9475 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc); | 9476 WriteBarrierMode mode = array->GetWriteBarrierMode(no_gc); |
| 9476 for (int i = 0; i < length; i++) { | 9477 for (int i = 0; i < length; i++) { |
| 9477 array->set(i, frame->GetParameter(i), mode); | 9478 array->set(i, frame->GetParameter(i), mode); |
| 9478 } | 9479 } |
| 9479 arguments->set_elements(*array); | 9480 arguments->set_elements(*array); |
| 9480 return arguments; | 9481 return arguments; |
| 9481 } | 9482 } |
| 9482 | 9483 |
| 9483 | 9484 |
| 9484 static const char* source_str = | 9485 static const char kSourceStr[] = |
| 9485 "(function(arguments,__source__){return eval(__source__);})"; | 9486 "(function(arguments,__source__){return eval(__source__);})"; |
| 9486 static const int source_str_length = StrLength(source_str); | |
| 9487 | 9487 |
| 9488 | 9488 |
| 9489 // Evaluate a piece of JavaScript in the context of a stack frame for | 9489 // Evaluate a piece of JavaScript in the context of a stack frame for |
| 9490 // debugging. This is accomplished by creating a new context which in its | 9490 // debugging. This is accomplished by creating a new context which in its |
| 9491 // extension part has all the parameters and locals of the function on the | 9491 // extension part has all the parameters and locals of the function on the |
| 9492 // stack frame. A function which calls eval with the code to evaluate is then | 9492 // stack frame. A function which calls eval with the code to evaluate is then |
| 9493 // compiled in this context and called in this context. As this context | 9493 // compiled in this context and called in this context. As this context |
| 9494 // replaces the context of the function on the stack frame a new (empty) | 9494 // replaces the context of the function on the stack frame a new (empty) |
| 9495 // function is created as well to be used as the closure for the context. | 9495 // function is created as well to be used as the closure for the context. |
| 9496 // This function and the context acts as replacements for the function on the | 9496 // This function and the context acts as replacements for the function on the |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9559 // Copy any with contexts present and chain them in front of this context. | 9559 // Copy any with contexts present and chain them in front of this context. |
| 9560 Handle<Context> frame_context(Context::cast(frame->context())); | 9560 Handle<Context> frame_context(Context::cast(frame->context())); |
| 9561 Handle<Context> function_context(frame_context->fcontext()); | 9561 Handle<Context> function_context(frame_context->fcontext()); |
| 9562 context = CopyWithContextChain(frame_context, context); | 9562 context = CopyWithContextChain(frame_context, context); |
| 9563 | 9563 |
| 9564 // Wrap the evaluation statement in a new function compiled in the newly | 9564 // Wrap the evaluation statement in a new function compiled in the newly |
| 9565 // created context. The function has one parameter which has to be called | 9565 // created context. The function has one parameter which has to be called |
| 9566 // 'arguments'. This it to have access to what would have been 'arguments' in | 9566 // 'arguments'. This it to have access to what would have been 'arguments' in |
| 9567 // the function being debugged. | 9567 // the function being debugged. |
| 9568 // function(arguments,__source__) {return eval(__source__);} | 9568 // function(arguments,__source__) {return eval(__source__);} |
| 9569 ASSERT(source_str_length == StrLength(source_str)); | |
| 9570 | 9569 |
| 9571 Handle<String> function_source = | 9570 Handle<String> function_source = |
| 9572 isolate->factory()->NewStringFromAscii( | 9571 isolate->factory()->NewStringFromAscii( |
| 9573 Vector<const char>(source_str, source_str_length)); | 9572 Vector<const char>(kSourceStr, sizeof(kSourceStr) - 1)); |
| 9574 Handle<SharedFunctionInfo> shared = | 9573 Handle<SharedFunctionInfo> shared = |
| 9575 Compiler::CompileEval(function_source, | 9574 Compiler::CompileEval(function_source, |
| 9576 context, | 9575 context, |
| 9577 context->IsGlobalContext(), | 9576 context->IsGlobalContext(), |
| 9578 Compiler::DONT_VALIDATE_JSON); | 9577 Compiler::DONT_VALIDATE_JSON); |
| 9579 if (shared.is_null()) return Failure::Exception(); | 9578 if (shared.is_null()) return Failure::Exception(); |
| 9580 Handle<JSFunction> compiled_function = | 9579 Handle<JSFunction> compiled_function = |
| 9581 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context); | 9580 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context); |
| 9582 | 9581 |
| 9583 // Invoke the result of the compilation to get the evaluation function. | 9582 // Invoke the result of the compilation to get the evaluation function. |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10339 int cursor = 0; | 10338 int cursor = 0; |
| 10340 int frames_seen = 0; | 10339 int frames_seen = 0; |
| 10341 while (!iter.done() && frames_seen < limit) { | 10340 while (!iter.done() && frames_seen < limit) { |
| 10342 StackFrame* raw_frame = iter.frame(); | 10341 StackFrame* raw_frame = iter.frame(); |
| 10343 if (ShowFrameInStackTrace(raw_frame, *caller, &seen_caller)) { | 10342 if (ShowFrameInStackTrace(raw_frame, *caller, &seen_caller)) { |
| 10344 frames_seen++; | 10343 frames_seen++; |
| 10345 JavaScriptFrame* frame = JavaScriptFrame::cast(raw_frame); | 10344 JavaScriptFrame* frame = JavaScriptFrame::cast(raw_frame); |
| 10346 Object* recv = frame->receiver(); | 10345 Object* recv = frame->receiver(); |
| 10347 Object* fun = frame->function(); | 10346 Object* fun = frame->function(); |
| 10348 Address pc = frame->pc(); | 10347 Address pc = frame->pc(); |
| 10349 Address start = frame->code()->address(); | 10348 Address start = frame->LookupCode(isolate)->address(); |
| 10350 Smi* offset = Smi::FromInt(static_cast<int>(pc - start)); | 10349 Smi* offset = Smi::FromInt(static_cast<int>(pc - start)); |
| 10351 FixedArray* elements = FixedArray::cast(result->elements()); | 10350 FixedArray* elements = FixedArray::cast(result->elements()); |
| 10352 if (cursor + 2 < elements->length()) { | 10351 if (cursor + 2 < elements->length()) { |
| 10353 elements->set(cursor++, recv); | 10352 elements->set(cursor++, recv); |
| 10354 elements->set(cursor++, fun); | 10353 elements->set(cursor++, fun); |
| 10355 elements->set(cursor++, offset); | 10354 elements->set(cursor++, offset); |
| 10356 } else { | 10355 } else { |
| 10357 HandleScope scope(isolate); | 10356 HandleScope scope(isolate); |
| 10358 Handle<Object> recv_handle(recv, isolate); | 10357 Handle<Object> recv_handle(recv, isolate); |
| 10359 Handle<Object> fun_handle(fun, isolate); | 10358 Handle<Object> fun_handle(fun, isolate); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10553 | 10552 |
| 10554 #define F(name, number_of_args, result_size) \ | 10553 #define F(name, number_of_args, result_size) \ |
| 10555 { Runtime::k##name, Runtime::RUNTIME, #name, \ | 10554 { Runtime::k##name, Runtime::RUNTIME, #name, \ |
| 10556 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size }, | 10555 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size }, |
| 10557 | 10556 |
| 10558 | 10557 |
| 10559 #define I(name, number_of_args, result_size) \ | 10558 #define I(name, number_of_args, result_size) \ |
| 10560 { Runtime::kInline##name, Runtime::INLINE, \ | 10559 { Runtime::kInline##name, Runtime::INLINE, \ |
| 10561 "_" #name, NULL, number_of_args, result_size }, | 10560 "_" #name, NULL, number_of_args, result_size }, |
| 10562 | 10561 |
| 10563 Runtime::Function kIntrinsicFunctions[] = { | 10562 static const Runtime::Function kIntrinsicFunctions[] = { |
| 10564 RUNTIME_FUNCTION_LIST(F) | 10563 RUNTIME_FUNCTION_LIST(F) |
| 10565 INLINE_FUNCTION_LIST(I) | 10564 INLINE_FUNCTION_LIST(I) |
| 10566 INLINE_RUNTIME_FUNCTION_LIST(I) | 10565 INLINE_RUNTIME_FUNCTION_LIST(I) |
| 10567 }; | 10566 }; |
| 10568 | 10567 |
| 10569 | 10568 |
| 10570 Object* Runtime::InitializeIntrinsicFunctionNames(Heap* heap, | 10569 Object* Runtime::InitializeIntrinsicFunctionNames(Heap* heap, |
| 10571 Object* dictionary) { | 10570 Object* dictionary) { |
| 10572 ASSERT(Isolate::Current()->heap() == heap); | 10571 ASSERT(Isolate::Current()->heap() == heap); |
| 10573 ASSERT(dictionary != NULL); | 10572 ASSERT(dictionary != NULL); |
| 10574 ASSERT(StringDictionary::cast(dictionary)->NumberOfElements() == 0); | 10573 ASSERT(StringDictionary::cast(dictionary)->NumberOfElements() == 0); |
| 10575 for (int i = 0; i < kNumFunctions; ++i) { | 10574 for (int i = 0; i < kNumFunctions; ++i) { |
| 10576 Object* name_symbol = heap->LookupAsciiSymbol(kIntrinsicFunctions[i].name); | 10575 Object* name_symbol = heap->LookupAsciiSymbol(kIntrinsicFunctions[i].name); |
| 10577 if (name_symbol->IsFailure()) return name_symbol; | 10576 if (name_symbol->IsFailure()) return name_symbol; |
| 10578 StringDictionary* string_dictionary = StringDictionary::cast(dictionary); | 10577 StringDictionary* string_dictionary = StringDictionary::cast(dictionary); |
| 10579 dictionary = string_dictionary->Add(String::cast(name_symbol), | 10578 dictionary = string_dictionary->Add(String::cast(name_symbol), |
| 10580 Smi::FromInt(i), | 10579 Smi::FromInt(i), |
| 10581 PropertyDetails(NONE, NORMAL)); | 10580 PropertyDetails(NONE, NORMAL)); |
| 10582 // Non-recoverable failure. Calling code must restart heap initialization. | 10581 // Non-recoverable failure. Calling code must restart heap initialization. |
| 10583 if (dictionary->IsFailure()) return dictionary; | 10582 if (dictionary->IsFailure()) return dictionary; |
| 10584 } | 10583 } |
| 10585 return dictionary; | 10584 return dictionary; |
| 10586 } | 10585 } |
| 10587 | 10586 |
| 10588 | 10587 |
| 10589 Runtime::Function* Runtime::FunctionForSymbol(Handle<String> name) { | 10588 const Runtime::Function* Runtime::FunctionForSymbol(Handle<String> name) { |
| 10590 Heap* heap = HEAP; | 10589 Heap* heap = HEAP; |
| 10591 int entry = heap->intrinsic_function_names()->FindEntry(*name); | 10590 int entry = heap->intrinsic_function_names()->FindEntry(*name); |
| 10592 if (entry != kNotFound) { | 10591 if (entry != kNotFound) { |
| 10593 Object* smi_index = heap->intrinsic_function_names()->ValueAt(entry); | 10592 Object* smi_index = heap->intrinsic_function_names()->ValueAt(entry); |
| 10594 int function_index = Smi::cast(smi_index)->value(); | 10593 int function_index = Smi::cast(smi_index)->value(); |
| 10595 return &(kIntrinsicFunctions[function_index]); | 10594 return &(kIntrinsicFunctions[function_index]); |
| 10596 } | 10595 } |
| 10597 return NULL; | 10596 return NULL; |
| 10598 } | 10597 } |
| 10599 | 10598 |
| 10600 | 10599 |
| 10601 Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 10600 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
| 10602 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 10601 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
| 10603 } | 10602 } |
| 10604 | 10603 |
| 10605 | 10604 |
| 10606 void Runtime::PerformGC(Object* result) { | 10605 void Runtime::PerformGC(Object* result) { |
| 10607 Failure* failure = Failure::cast(result); | 10606 Failure* failure = Failure::cast(result); |
| 10608 if (failure->IsRetryAfterGC()) { | 10607 if (failure->IsRetryAfterGC()) { |
| 10609 // Try to do a garbage collection; ignore it if it fails. The C | 10608 // Try to do a garbage collection; ignore it if it fails. The C |
| 10610 // entry stub will throw an out-of-memory exception in that case. | 10609 // entry stub will throw an out-of-memory exception in that case. |
| 10611 HEAP->CollectGarbage(failure->requested(), failure->allocation_space()); | 10610 HEAP->CollectGarbage(failure->requested(), failure->allocation_space()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 10626 #define SETUP_RUNTIME_ENTRIES(Name, argc, resize) \ | 10625 #define SETUP_RUNTIME_ENTRIES(Name, argc, resize) \ |
| 10627 entries_[lut_index].method = &CodeGenerator::Generate##Name; \ | 10626 entries_[lut_index].method = &CodeGenerator::Generate##Name; \ |
| 10628 entries_[lut_index].name = "_" #Name; \ | 10627 entries_[lut_index].name = "_" #Name; \ |
| 10629 entries_[lut_index++].nargs = argc; | 10628 entries_[lut_index++].nargs = argc; |
| 10630 INLINE_RUNTIME_FUNCTION_LIST(SETUP_RUNTIME_ENTRIES); | 10629 INLINE_RUNTIME_FUNCTION_LIST(SETUP_RUNTIME_ENTRIES); |
| 10631 #undef SETUP_RUNTIME_ENTRIES | 10630 #undef SETUP_RUNTIME_ENTRIES |
| 10632 } | 10631 } |
| 10633 | 10632 |
| 10634 | 10633 |
| 10635 } } // namespace v8::internal | 10634 } } // namespace v8::internal |
| OLD | NEW |