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 6620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6631 bool has_pending_exception; | 6631 bool has_pending_exception; |
6632 Handle<Object> receiver = Top::global(); | 6632 Handle<Object> receiver = Top::global(); |
6633 Handle<Object> result = | 6633 Handle<Object> result = |
6634 Execution::Call(compiled_function, receiver, 0, NULL, | 6634 Execution::Call(compiled_function, receiver, 0, NULL, |
6635 &has_pending_exception); | 6635 &has_pending_exception); |
6636 if (has_pending_exception) return Failure::Exception(); | 6636 if (has_pending_exception) return Failure::Exception(); |
6637 return *result; | 6637 return *result; |
6638 } | 6638 } |
6639 | 6639 |
6640 | 6640 |
6641 // If an object given is an external string, check that the underlying | |
6642 // resource is accessible. For other kinds of objects, always return true. | |
6643 static bool IsExternalStringValid(Object* str) { | |
6644 if (!str->IsString() || !StringShape(String::cast(str)).IsExternal()) { | |
6645 return true; | |
6646 } | |
6647 if (String::cast(str)->IsAsciiRepresentation()) { | |
6648 return ExternalAsciiString::cast(str)->resource() != NULL; | |
6649 } else if (String::cast(str)->IsTwoByteRepresentation()) { | |
6650 return ExternalTwoByteString::cast(str)->resource() != NULL; | |
6651 } else { | |
6652 return true; | |
6653 } | |
6654 } | |
6655 | |
6656 | |
6657 // Helper function used by Runtime_DebugGetLoadedScripts below. | |
6658 static int DebugGetLoadedScripts(FixedArray* instances, int instances_size) { | |
6659 NoHandleAllocation ha; | |
6660 AssertNoAllocation no_alloc; | |
6661 | |
6662 // Scan heap for Script objects. | |
6663 int count = 0; | |
6664 HeapIterator iterator; | |
6665 while (iterator.has_next()) { | |
6666 HeapObject* obj = iterator.next(); | |
6667 ASSERT(obj != NULL); | |
6668 if (obj->IsScript() && IsExternalStringValid(Script::cast(obj)->source())) { | |
6669 if (instances != NULL && count < instances_size) { | |
6670 instances->set(count, obj); | |
6671 } | |
6672 count++; | |
6673 } | |
6674 } | |
6675 | |
6676 return count; | |
6677 } | |
6678 | |
6679 | |
6680 static Object* Runtime_DebugGetLoadedScripts(Arguments args) { | 6641 static Object* Runtime_DebugGetLoadedScripts(Arguments args) { |
6681 HandleScope scope; | 6642 HandleScope scope; |
6682 ASSERT(args.length() == 0); | 6643 ASSERT(args.length() == 0); |
6683 | 6644 |
6684 // Perform two GCs to get rid of all unreferenced scripts. The first GC gets | |
6685 // rid of all the cached script wrappers and the second gets rid of the | |
6686 // scripts which is no longer referenced. | |
6687 Heap::CollectAllGarbage(); | |
6688 Heap::CollectAllGarbage(); | |
6689 | |
6690 // Get the number of scripts. | |
6691 int count; | |
6692 count = DebugGetLoadedScripts(NULL, 0); | |
6693 | |
6694 // Allocate an array to hold the result. | |
6695 Handle<FixedArray> instances = Factory::NewFixedArray(count); | |
6696 | |
6697 // Fill the script objects. | 6645 // Fill the script objects. |
6698 count = DebugGetLoadedScripts(*instances, count); | 6646 Handle<FixedArray> instances = Debug::GetLoadedScripts(); |
6699 | 6647 |
6700 // Convert the script objects to proper JS objects. | 6648 // Convert the script objects to proper JS objects. |
6701 for (int i = 0; i < count; i++) { | 6649 for (int i = 0; i < instances->length(); i++) { |
6702 Handle<Script> script = Handle<Script>(Script::cast(instances->get(i))); | 6650 Handle<Script> script = Handle<Script>(Script::cast(instances->get(i))); |
6703 // Get the script wrapper in a local handle before calling GetScriptWrapper, | 6651 // Get the script wrapper in a local handle before calling GetScriptWrapper, |
6704 // because using | 6652 // because using |
6705 // instances->set(i, *GetScriptWrapper(script)) | 6653 // instances->set(i, *GetScriptWrapper(script)) |
6706 // is unsafe as GetScriptWrapper might call GC and the C++ compiler might | 6654 // is unsafe as GetScriptWrapper might call GC and the C++ compiler might |
6707 // already have deferenced the instances handle. | 6655 // already have deferenced the instances handle. |
6708 Handle<JSValue> wrapper = GetScriptWrapper(script); | 6656 Handle<JSValue> wrapper = GetScriptWrapper(script); |
6709 instances->set(i, *wrapper); | 6657 instances->set(i, *wrapper); |
6710 } | 6658 } |
6711 | 6659 |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7083 } else { | 7031 } else { |
7084 // Handle last resort GC and make sure to allow future allocations | 7032 // Handle last resort GC and make sure to allow future allocations |
7085 // to grow the heap without causing GCs (if possible). | 7033 // to grow the heap without causing GCs (if possible). |
7086 Counters::gc_last_resort_from_js.Increment(); | 7034 Counters::gc_last_resort_from_js.Increment(); |
7087 Heap::CollectAllGarbage(); | 7035 Heap::CollectAllGarbage(); |
7088 } | 7036 } |
7089 } | 7037 } |
7090 | 7038 |
7091 | 7039 |
7092 } } // namespace v8::internal | 7040 } } // namespace v8::internal |
OLD | NEW |