OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 // Defined when linking against shared lib on Windows. | 6 // Defined when linking against shared lib on Windows. |
7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) | 7 #if defined(USING_V8_SHARED) && !defined(V8_SHARED) |
8 #define V8_SHARED | 8 #define V8_SHARED |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 #define DCHECK(condition) assert(condition) | 66 #define DCHECK(condition) assert(condition) |
67 #endif | 67 #endif |
68 | 68 |
69 #ifndef CHECK | 69 #ifndef CHECK |
70 #define CHECK(condition) assert(condition) | 70 #define CHECK(condition) assert(condition) |
71 #endif | 71 #endif |
72 | 72 |
73 namespace v8 { | 73 namespace v8 { |
74 | 74 |
75 namespace { | 75 namespace { |
| 76 |
| 77 const int MB = 1024 * 1024; |
| 78 |
| 79 |
| 80 class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
| 81 public: |
| 82 virtual void* Allocate(size_t length) { |
| 83 void* data = AllocateUninitialized(length); |
| 84 return data == NULL ? data : memset(data, 0, length); |
| 85 } |
| 86 virtual void* AllocateUninitialized(size_t length) { return malloc(length); } |
| 87 virtual void Free(void* data, size_t) { free(data); } |
| 88 }; |
| 89 |
| 90 |
| 91 class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator { |
| 92 public: |
| 93 void* Allocate(size_t length) override { |
| 94 size_t actual_length = length > 10 * MB ? 1 : length; |
| 95 void* data = AllocateUninitialized(actual_length); |
| 96 return data == NULL ? data : memset(data, 0, actual_length); |
| 97 } |
| 98 void* AllocateUninitialized(size_t length) override { |
| 99 return length > 10 * MB ? malloc(1) : malloc(length); |
| 100 } |
| 101 void Free(void* p, size_t) override { free(p); } |
| 102 }; |
| 103 |
| 104 |
76 v8::Platform* g_platform = NULL; | 105 v8::Platform* g_platform = NULL; |
| 106 |
77 } // namespace | 107 } // namespace |
78 | 108 |
79 | 109 |
80 static Handle<Value> Throw(Isolate* isolate, const char* message) { | 110 static Handle<Value> Throw(Isolate* isolate, const char* message) { |
81 return isolate->ThrowException(String::NewFromUtf8(isolate, message)); | 111 return isolate->ThrowException(String::NewFromUtf8(isolate, message)); |
82 } | 112 } |
83 | 113 |
84 | 114 |
85 | 115 |
86 class PerIsolateData { | 116 class PerIsolateData { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 CounterCollection* Shell::counters_ = &local_counters_; | 189 CounterCollection* Shell::counters_ = &local_counters_; |
160 base::Mutex Shell::context_mutex_; | 190 base::Mutex Shell::context_mutex_; |
161 const base::TimeTicks Shell::kInitialTicks = | 191 const base::TimeTicks Shell::kInitialTicks = |
162 base::TimeTicks::HighResolutionNow(); | 192 base::TimeTicks::HighResolutionNow(); |
163 Persistent<Context> Shell::utility_context_; | 193 Persistent<Context> Shell::utility_context_; |
164 #endif // !V8_SHARED | 194 #endif // !V8_SHARED |
165 | 195 |
166 Persistent<Context> Shell::evaluation_context_; | 196 Persistent<Context> Shell::evaluation_context_; |
167 ShellOptions Shell::options; | 197 ShellOptions Shell::options; |
168 const char* Shell::kPrompt = "d8> "; | 198 const char* Shell::kPrompt = "d8> "; |
169 const int MB = 1024 * 1024; | |
170 | 199 |
171 #ifndef V8_SHARED | 200 #ifndef V8_SHARED |
172 bool CounterMap::Match(void* key1, void* key2) { | 201 bool CounterMap::Match(void* key1, void* key2) { |
173 const char* name1 = reinterpret_cast<const char*>(key1); | 202 const char* name1 = reinterpret_cast<const char*>(key1); |
174 const char* name2 = reinterpret_cast<const char*>(key2); | 203 const char* name2 = reinterpret_cast<const char*>(key2); |
175 return strcmp(name1, name2) == 0; | 204 return strcmp(name1, name2) == 0; |
176 } | 205 } |
177 #endif // !V8_SHARED | 206 #endif // !V8_SHARED |
178 | 207 |
179 | 208 |
(...skipping 10 matching lines...) Expand all Loading... |
190 uint16_t* source_buffer = new uint16_t[source_length]; | 219 uint16_t* source_buffer = new uint16_t[source_length]; |
191 source->Write(source_buffer, 0, source_length); | 220 source->Write(source_buffer, 0, source_length); |
192 int name_length = 0; | 221 int name_length = 0; |
193 uint16_t* name_buffer = NULL; | 222 uint16_t* name_buffer = NULL; |
194 if (name->IsString()) { | 223 if (name->IsString()) { |
195 Local<String> name_string = Local<String>::Cast(name); | 224 Local<String> name_string = Local<String>::Cast(name); |
196 name_length = name_string->Length(); | 225 name_length = name_string->Length(); |
197 name_buffer = new uint16_t[name_length]; | 226 name_buffer = new uint16_t[name_length]; |
198 name_string->Write(name_buffer, 0, name_length); | 227 name_string->Write(name_buffer, 0, name_length); |
199 } | 228 } |
200 Isolate* temp_isolate = Isolate::New(); | 229 ShellArrayBufferAllocator allocator; |
| 230 Isolate::CreateParams create_params; |
| 231 create_params.array_buffer_allocator = &allocator; |
| 232 Isolate* temp_isolate = Isolate::New(create_params); |
201 ScriptCompiler::CachedData* result = NULL; | 233 ScriptCompiler::CachedData* result = NULL; |
202 { | 234 { |
203 Isolate::Scope isolate_scope(temp_isolate); | 235 Isolate::Scope isolate_scope(temp_isolate); |
204 HandleScope handle_scope(temp_isolate); | 236 HandleScope handle_scope(temp_isolate); |
205 Context::Scope context_scope(Context::New(temp_isolate)); | 237 Context::Scope context_scope(Context::New(temp_isolate)); |
206 Local<String> source_copy = v8::String::NewFromTwoByte( | 238 Local<String> source_copy = v8::String::NewFromTwoByte( |
207 temp_isolate, source_buffer, v8::String::kNormalString, source_length); | 239 temp_isolate, source_buffer, v8::String::kNormalString, source_length); |
208 Local<Value> name_copy; | 240 Local<Value> name_copy; |
209 if (name_buffer) { | 241 if (name_buffer) { |
210 name_copy = v8::String::NewFromTwoByte( | 242 name_copy = v8::String::NewFromTwoByte( |
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 base::Thread::Options SourceGroup::GetThreadOptions() { | 1312 base::Thread::Options SourceGroup::GetThreadOptions() { |
1281 // On some systems (OSX 10.6) the stack size default is 0.5Mb or less | 1313 // On some systems (OSX 10.6) the stack size default is 0.5Mb or less |
1282 // which is not enough to parse the big literal expressions used in tests. | 1314 // which is not enough to parse the big literal expressions used in tests. |
1283 // The stack size should be at least StackGuard::kLimitSize + some | 1315 // The stack size should be at least StackGuard::kLimitSize + some |
1284 // OS-specific padding for thread startup code. 2Mbytes seems to be enough. | 1316 // OS-specific padding for thread startup code. 2Mbytes seems to be enough. |
1285 return base::Thread::Options("IsolateThread", 2 * MB); | 1317 return base::Thread::Options("IsolateThread", 2 * MB); |
1286 } | 1318 } |
1287 | 1319 |
1288 | 1320 |
1289 void SourceGroup::ExecuteInThread() { | 1321 void SourceGroup::ExecuteInThread() { |
1290 Isolate* isolate = Isolate::New(); | 1322 ShellArrayBufferAllocator allocator; |
| 1323 Isolate::CreateParams create_params; |
| 1324 create_params.array_buffer_allocator = &allocator; |
| 1325 Isolate* isolate = Isolate::New(create_params); |
1291 do { | 1326 do { |
1292 next_semaphore_.Wait(); | 1327 next_semaphore_.Wait(); |
1293 { | 1328 { |
1294 Isolate::Scope iscope(isolate); | 1329 Isolate::Scope iscope(isolate); |
1295 { | 1330 { |
1296 HandleScope scope(isolate); | 1331 HandleScope scope(isolate); |
1297 PerIsolateData data(isolate); | 1332 PerIsolateData data(isolate); |
1298 Local<Context> context = Shell::CreateEvaluationContext(isolate); | 1333 Local<Context> context = Shell::CreateEvaluationContext(isolate); |
1299 { | 1334 { |
1300 Context::Scope cscope(context); | 1335 Context::Scope cscope(context); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 if (n == NULL) continue; | 1612 if (n == NULL) continue; |
1578 printf(" (\"%s\", 0x%05" V8PRIxPTR "): \"%s\",\n", sname, p, n); | 1613 printf(" (\"%s\", 0x%05" V8PRIxPTR "): \"%s\",\n", sname, p, n); |
1579 } | 1614 } |
1580 } | 1615 } |
1581 printf("}\n"); | 1616 printf("}\n"); |
1582 #undef ROOT_LIST_CASE | 1617 #undef ROOT_LIST_CASE |
1583 } | 1618 } |
1584 #endif // !V8_SHARED | 1619 #endif // !V8_SHARED |
1585 | 1620 |
1586 | 1621 |
1587 class ShellArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | |
1588 public: | |
1589 virtual void* Allocate(size_t length) { | |
1590 void* data = AllocateUninitialized(length); | |
1591 return data == NULL ? data : memset(data, 0, length); | |
1592 } | |
1593 virtual void* AllocateUninitialized(size_t length) { return malloc(length); } | |
1594 virtual void Free(void* data, size_t) { free(data); } | |
1595 }; | |
1596 | |
1597 | |
1598 class MockArrayBufferAllocator : public v8::ArrayBuffer::Allocator { | |
1599 public: | |
1600 void* Allocate(size_t length) override { | |
1601 size_t actual_length = length > 10 * MB ? 1 : length; | |
1602 void* data = AllocateUninitialized(actual_length); | |
1603 return data == NULL ? data : memset(data, 0, actual_length); | |
1604 } | |
1605 void* AllocateUninitialized(size_t length) override { | |
1606 return length > 10 * MB ? malloc(1) : malloc(length); | |
1607 } | |
1608 void Free(void* p, size_t) override { free(p); } | |
1609 }; | |
1610 | |
1611 | |
1612 int Shell::Main(int argc, char* argv[]) { | 1622 int Shell::Main(int argc, char* argv[]) { |
1613 #if (defined(_WIN32) || defined(_WIN64)) | 1623 #if (defined(_WIN32) || defined(_WIN64)) |
1614 UINT new_flags = | 1624 UINT new_flags = |
1615 SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX; | 1625 SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX; |
1616 UINT existing_flags = SetErrorMode(new_flags); | 1626 UINT existing_flags = SetErrorMode(new_flags); |
1617 SetErrorMode(existing_flags | new_flags); | 1627 SetErrorMode(existing_flags | new_flags); |
1618 #if defined(_MSC_VER) | 1628 #if defined(_MSC_VER) |
1619 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); | 1629 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); |
1620 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); | 1630 _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR); |
1621 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); | 1631 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); |
1622 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); | 1632 _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR); |
1623 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); | 1633 _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE); |
1624 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); | 1634 _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); |
1625 _set_error_mode(_OUT_TO_STDERR); | 1635 _set_error_mode(_OUT_TO_STDERR); |
1626 #endif // defined(_MSC_VER) | 1636 #endif // defined(_MSC_VER) |
1627 #endif // defined(_WIN32) || defined(_WIN64) | 1637 #endif // defined(_WIN32) || defined(_WIN64) |
1628 if (!SetOptions(argc, argv)) return 1; | 1638 if (!SetOptions(argc, argv)) return 1; |
1629 v8::V8::InitializeICU(options.icu_data_file); | 1639 v8::V8::InitializeICU(options.icu_data_file); |
1630 g_platform = v8::platform::CreateDefaultPlatform(); | 1640 g_platform = v8::platform::CreateDefaultPlatform(); |
1631 v8::V8::InitializePlatform(g_platform); | 1641 v8::V8::InitializePlatform(g_platform); |
1632 v8::V8::Initialize(); | 1642 v8::V8::Initialize(); |
1633 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 1643 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
1634 v8::StartupDataHandler startup_data(argv[0], options.natives_blob, | 1644 v8::StartupDataHandler startup_data(argv[0], options.natives_blob, |
1635 options.snapshot_blob); | 1645 options.snapshot_blob); |
1636 #endif | 1646 #endif |
1637 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg"); | 1647 SetFlagsFromString("--trace-hydrogen-file=hydrogen.cfg"); |
1638 SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg"); | 1648 SetFlagsFromString("--trace-turbo-cfg-file=turbo.cfg"); |
1639 SetFlagsFromString("--redirect-code-traces-to=code.asm"); | 1649 SetFlagsFromString("--redirect-code-traces-to=code.asm"); |
| 1650 int result = 0; |
| 1651 Isolate::CreateParams create_params; |
1640 ShellArrayBufferAllocator array_buffer_allocator; | 1652 ShellArrayBufferAllocator array_buffer_allocator; |
1641 MockArrayBufferAllocator mock_arraybuffer_allocator; | 1653 MockArrayBufferAllocator mock_arraybuffer_allocator; |
1642 if (options.mock_arraybuffer_allocator) { | 1654 if (options.mock_arraybuffer_allocator) { |
1643 v8::V8::SetArrayBufferAllocator(&mock_arraybuffer_allocator); | 1655 create_params.array_buffer_allocator = &mock_arraybuffer_allocator; |
1644 } else { | 1656 } else { |
1645 v8::V8::SetArrayBufferAllocator(&array_buffer_allocator); | 1657 create_params.array_buffer_allocator = &array_buffer_allocator; |
1646 } | 1658 } |
1647 int result = 0; | |
1648 Isolate::CreateParams create_params; | |
1649 #if !defined(V8_SHARED) && defined(ENABLE_GDB_JIT_INTERFACE) | 1659 #if !defined(V8_SHARED) && defined(ENABLE_GDB_JIT_INTERFACE) |
1650 if (i::FLAG_gdbjit) { | 1660 if (i::FLAG_gdbjit) { |
1651 create_params.code_event_handler = i::GDBJITInterface::EventHandler; | 1661 create_params.code_event_handler = i::GDBJITInterface::EventHandler; |
1652 } | 1662 } |
1653 #endif | 1663 #endif |
1654 #ifdef ENABLE_VTUNE_JIT_INTERFACE | 1664 #ifdef ENABLE_VTUNE_JIT_INTERFACE |
1655 create_params.code_event_handler = vTune::GetVtuneCodeEventHandler(); | 1665 create_params.code_event_handler = vTune::GetVtuneCodeEventHandler(); |
1656 #endif | 1666 #endif |
1657 #ifndef V8_SHARED | 1667 #ifndef V8_SHARED |
1658 create_params.constraints.ConfigureDefaults( | 1668 create_params.constraints.ConfigureDefaults( |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1736 } | 1746 } |
1737 | 1747 |
1738 } // namespace v8 | 1748 } // namespace v8 |
1739 | 1749 |
1740 | 1750 |
1741 #ifndef GOOGLE3 | 1751 #ifndef GOOGLE3 |
1742 int main(int argc, char* argv[]) { | 1752 int main(int argc, char* argv[]) { |
1743 return v8::Shell::Main(argc, argv); | 1753 return v8::Shell::Main(argc, argv); |
1744 } | 1754 } |
1745 #endif | 1755 #endif |
OLD | NEW |