| 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 #include <stdlib.h> | 5 #include <stdlib.h> |
| 6 | 6 |
| 7 #include <sstream> |
| 8 #include <string> |
| 9 |
| 7 #include "src/v8.h" | 10 #include "src/v8.h" |
| 8 | 11 |
| 9 #include "src/ast.h" | 12 #include "src/ast.h" |
| 10 #include "src/base/platform/platform.h" | 13 #include "src/base/platform/platform.h" |
| 11 #include "src/base/utils/random-number-generator.h" | 14 #include "src/base/utils/random-number-generator.h" |
| 12 #include "src/bootstrapper.h" | 15 #include "src/bootstrapper.h" |
| 13 #include "src/codegen.h" | 16 #include "src/codegen.h" |
| 14 #include "src/compilation-cache.h" | 17 #include "src/compilation-cache.h" |
| 15 #include "src/cpu-profiler.h" | 18 #include "src/cpu-profiler.h" |
| 16 #include "src/debug.h" | 19 #include "src/debug.h" |
| (...skipping 2322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2339 } | 2342 } |
| 2340 | 2343 |
| 2341 | 2344 |
| 2342 void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) { | 2345 void Isolate::CountUsage(v8::Isolate::UseCounterFeature feature) { |
| 2343 if (use_counter_callback_) { | 2346 if (use_counter_callback_) { |
| 2344 use_counter_callback_(reinterpret_cast<v8::Isolate*>(this), feature); | 2347 use_counter_callback_(reinterpret_cast<v8::Isolate*>(this), feature); |
| 2345 } | 2348 } |
| 2346 } | 2349 } |
| 2347 | 2350 |
| 2348 | 2351 |
| 2352 void Isolate::CodeCreateEvent(Code* code, |
| 2353 const char* comment) { |
| 2354 if (code_event_handler() == NULL) return; |
| 2355 code_event_handler()->Create(code->address(), |
| 2356 code->ExecutableSize(), |
| 2357 comment); |
| 2358 } |
| 2359 |
| 2360 |
| 2361 namespace { |
| 2362 void AppendVA(char* buf, int buf_size, const char* format, ...) { |
| 2363 va_list args; |
| 2364 va_start(args, format); |
| 2365 Vector<char> v(buf, buf_size); |
| 2366 v8::internal::VSNPrintF(v, format, args); |
| 2367 } |
| 2368 |
| 2369 void AppendStringToStdString(String* str, std::string* std_str) { |
| 2370 if (str == NULL) return; |
| 2371 DisallowHeapAllocation no_gc; // Ensure string stay valid. |
| 2372 |
| 2373 int len = str->length(); |
| 2374 if (len > 0x1000) |
| 2375 len = 0x1000; |
| 2376 for (int i = 0; i < len; i++) { |
| 2377 uc32 c = str->Get(i); |
| 2378 if (c > 0xff) { |
| 2379 char buf[8]; |
| 2380 AppendVA(buf, 8, "\\u%04x", c); |
| 2381 std_str->append(buf); |
| 2382 } else if (c < 32 || c > 126) { |
| 2383 char buf[6]; |
| 2384 snprintf(buf, sizeof(buf), "\\x%02x", c); |
| 2385 std_str->append(buf); |
| 2386 } else if (c == ',') { |
| 2387 std_str->append("\\,"); |
| 2388 } else if (c == '\\') { |
| 2389 std_str->append("\\\\"); |
| 2390 } else if (c == '\"') { |
| 2391 std_str->append("\"\""); |
| 2392 } else { |
| 2393 char buf[3]; |
| 2394 AppendVA(buf, 3, "%lc", c); |
| 2395 std_str->append(buf); |
| 2396 } |
| 2397 } |
| 2398 } |
| 2399 |
| 2400 void AppendNameToStdString(Name* name, std::string* str) { |
| 2401 if (name->IsString()) { |
| 2402 AppendStringToStdString(String::cast(name), str); |
| 2403 } else { |
| 2404 Symbol* symbol = Symbol::cast(name); |
| 2405 str->append("symbol("); |
| 2406 if (!symbol->name()->IsUndefined()) { |
| 2407 str->append("\""); |
| 2408 AppendStringToStdString(String::cast(symbol->name()), str); |
| 2409 str->append("\" "); |
| 2410 } |
| 2411 char buf[20]; |
| 2412 AppendVA(buf, 20, "hash %x)", symbol->Hash()); |
| 2413 str->append(buf); |
| 2414 } |
| 2415 } |
| 2416 } |
| 2417 |
| 2418 |
| 2419 void Isolate::CodeCreateEvent(Code* code, |
| 2420 Name* name) { |
| 2421 if (code_event_handler() == NULL) return; |
| 2422 std::string code_name; |
| 2423 AppendNameToStdString(name, &code_name); |
| 2424 code_event_handler()->Create(code->address(), |
| 2425 code->ExecutableSize(), |
| 2426 code_name); |
| 2427 } |
| 2428 |
| 2429 |
| 2430 void Isolate::CodeCreateEvent(Code* code, |
| 2431 String* regexp_source) { |
| 2432 if (code_event_handler() == NULL) return; |
| 2433 std::string code_name; |
| 2434 AppendStringToStdString(regexp_source, &code_name); |
| 2435 code_event_handler()->Create(code->address(), |
| 2436 code->ExecutableSize(), |
| 2437 code_name); |
| 2438 } |
| 2439 |
| 2440 |
| 2441 void Isolate::CodeCreateEvent(Code* code, |
| 2442 SharedFunctionInfo* shared, |
| 2443 Name* source, int line, int column) { |
| 2444 if (code_event_handler() == NULL) return; |
| 2445 std::string code_name; |
| 2446 SmartArrayPointer<char> name = |
| 2447 shared->DebugName()->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 2448 code_name.append(name.get()); |
| 2449 code_name.append(" "); |
| 2450 AppendNameToStdString(source, &code_name); |
| 2451 std::ostringstream os; |
| 2452 os << ":" << line << ":" << column; |
| 2453 code_name += os.str(); |
| 2454 code_event_handler()->Create(code->address(), |
| 2455 code->ExecutableSize(), |
| 2456 code_name); |
| 2457 } |
| 2458 |
| 2459 |
| 2460 void Isolate::CodeCreateEvent(Address from, |
| 2461 const char* name_prefix, |
| 2462 Name* name) { |
| 2463 if (code_event_handler() == NULL) return; |
| 2464 std::string code_name; |
| 2465 code_name.append(name_prefix); |
| 2466 AppendNameToStdString(name, &code_name); |
| 2467 code_event_handler()->Create(from, |
| 2468 1, |
| 2469 code_name); |
| 2470 } |
| 2471 |
| 2472 |
| 2349 bool StackLimitCheck::JsHasOverflowed() const { | 2473 bool StackLimitCheck::JsHasOverflowed() const { |
| 2350 StackGuard* stack_guard = isolate_->stack_guard(); | 2474 StackGuard* stack_guard = isolate_->stack_guard(); |
| 2351 #ifdef USE_SIMULATOR | 2475 #ifdef USE_SIMULATOR |
| 2352 // The simulator uses a separate JS stack. | 2476 // The simulator uses a separate JS stack. |
| 2353 Address jssp_address = Simulator::current(isolate_)->get_sp(); | 2477 Address jssp_address = Simulator::current(isolate_)->get_sp(); |
| 2354 uintptr_t jssp = reinterpret_cast<uintptr_t>(jssp_address); | 2478 uintptr_t jssp = reinterpret_cast<uintptr_t>(jssp_address); |
| 2355 if (jssp < stack_guard->real_jslimit()) return true; | 2479 if (jssp < stack_guard->real_jslimit()) return true; |
| 2356 #endif // USE_SIMULATOR | 2480 #endif // USE_SIMULATOR |
| 2357 return reinterpret_cast<uintptr_t>(this) < stack_guard->real_climit(); | 2481 return reinterpret_cast<uintptr_t>(this) < stack_guard->real_climit(); |
| 2358 } | 2482 } |
| 2359 | 2483 |
| 2360 | 2484 |
| 2361 bool PostponeInterruptsScope::Intercept(StackGuard::InterruptFlag flag) { | 2485 bool PostponeInterruptsScope::Intercept(StackGuard::InterruptFlag flag) { |
| 2362 // First check whether the previous scope intercepts. | 2486 // First check whether the previous scope intercepts. |
| 2363 if (prev_ && prev_->Intercept(flag)) return true; | 2487 if (prev_ && prev_->Intercept(flag)) return true; |
| 2364 // Then check whether this scope intercepts. | 2488 // Then check whether this scope intercepts. |
| 2365 if ((flag & intercept_mask_)) { | 2489 if ((flag & intercept_mask_)) { |
| 2366 intercepted_flags_ |= flag; | 2490 intercepted_flags_ |= flag; |
| 2367 return true; | 2491 return true; |
| 2368 } | 2492 } |
| 2369 return false; | 2493 return false; |
| 2370 } | 2494 } |
| 2371 | 2495 |
| 2372 } } // namespace v8::internal | 2496 } } // namespace v8::internal |
| OLD | NEW |