OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 10 matching lines...) Expand all Loading... |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_RUNTIME_H_ | 28 #ifndef V8_RUNTIME_H_ |
29 #define V8_RUNTIME_H_ | 29 #define V8_RUNTIME_H_ |
30 | 30 |
| 31 #include "zone.h" |
| 32 |
31 namespace v8 { | 33 namespace v8 { |
32 namespace internal { | 34 namespace internal { |
33 | 35 |
34 // The interface to C++ runtime functions. | 36 // The interface to C++ runtime functions. |
35 | 37 |
36 // ---------------------------------------------------------------------------- | 38 // ---------------------------------------------------------------------------- |
37 // RUNTIME_FUNCTION_LIST_ALWAYS defines runtime calls available in both | 39 // RUNTIME_FUNCTION_LIST_ALWAYS defines runtime calls available in both |
38 // release and debug mode. | 40 // release and debug mode. |
39 // This macro should only be used by the macro RUNTIME_FUNCTION_LIST. | 41 // This macro should only be used by the macro RUNTIME_FUNCTION_LIST. |
40 | 42 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 #endif | 407 #endif |
406 | 408 |
407 #ifdef DEBUG | 409 #ifdef DEBUG |
408 #define RUNTIME_FUNCTION_LIST_DEBUG(F) \ | 410 #define RUNTIME_FUNCTION_LIST_DEBUG(F) \ |
409 /* Testing */ \ | 411 /* Testing */ \ |
410 F(ListNatives, 0, 1) | 412 F(ListNatives, 0, 1) |
411 #else | 413 #else |
412 #define RUNTIME_FUNCTION_LIST_DEBUG(F) | 414 #define RUNTIME_FUNCTION_LIST_DEBUG(F) |
413 #endif | 415 #endif |
414 | 416 |
415 | |
416 // ---------------------------------------------------------------------------- | 417 // ---------------------------------------------------------------------------- |
417 // RUNTIME_FUNCTION_LIST defines all runtime functions accessed | 418 // RUNTIME_FUNCTION_LIST defines all runtime functions accessed |
418 // either directly by id (via the code generator), or indirectly | 419 // either directly by id (via the code generator), or indirectly |
419 // via a native call by name (from within JS code). | 420 // via a native call by name (from within JS code). |
420 | 421 |
421 #define RUNTIME_FUNCTION_LIST(F) \ | 422 #define RUNTIME_FUNCTION_LIST(F) \ |
422 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \ | 423 RUNTIME_FUNCTION_LIST_ALWAYS_1(F) \ |
423 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \ | 424 RUNTIME_FUNCTION_LIST_ALWAYS_2(F) \ |
424 RUNTIME_FUNCTION_LIST_DEBUG(F) \ | 425 RUNTIME_FUNCTION_LIST_DEBUG(F) \ |
425 RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \ | 426 RUNTIME_FUNCTION_LIST_DEBUGGER_SUPPORT(F) \ |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 F(RegExpExec, 4, 1) \ | 476 F(RegExpExec, 4, 1) \ |
476 F(RegExpConstructResult, 3, 1) \ | 477 F(RegExpConstructResult, 3, 1) \ |
477 F(GetFromCache, 2, 1) \ | 478 F(GetFromCache, 2, 1) \ |
478 F(NumberToString, 1, 1) \ | 479 F(NumberToString, 1, 1) \ |
479 F(SwapElements, 3, 1) | 480 F(SwapElements, 3, 1) |
480 | 481 |
481 | 482 |
482 //--------------------------------------------------------------------------- | 483 //--------------------------------------------------------------------------- |
483 // Runtime provides access to all C++ runtime functions. | 484 // Runtime provides access to all C++ runtime functions. |
484 | 485 |
| 486 class RuntimeState { |
| 487 public: |
| 488 |
| 489 StaticResource<StringInputBuffer>* string_input_buffer() { |
| 490 return &string_input_buffer_; |
| 491 } |
| 492 unibrow::Mapping<unibrow::ToUppercase, 128>* to_upper_mapping() { |
| 493 return &to_upper_mapping_; |
| 494 } |
| 495 unibrow::Mapping<unibrow::ToLowercase, 128>* to_lower_mapping() { |
| 496 return &to_lower_mapping_; |
| 497 } |
| 498 StringInputBuffer* string_input_buffer_compare_bufx() { |
| 499 return &string_input_buffer_compare_bufx_; |
| 500 } |
| 501 StringInputBuffer* string_input_buffer_compare_bufy() { |
| 502 return &string_input_buffer_compare_bufy_; |
| 503 } |
| 504 StringInputBuffer* string_locale_compare_buf1() { |
| 505 return &string_locale_compare_buf1_; |
| 506 } |
| 507 StringInputBuffer* string_locale_compare_buf2() { |
| 508 return &string_locale_compare_buf2_; |
| 509 } |
| 510 int* smi_lexicographic_compare_x_elms() { |
| 511 return smi_lexicographic_compare_x_elms_; |
| 512 } |
| 513 int* smi_lexicographic_compare_y_elms() { |
| 514 return smi_lexicographic_compare_y_elms_; |
| 515 } |
| 516 |
| 517 private: |
| 518 RuntimeState() {} |
| 519 // Non-reentrant string buffer for efficient general use in the runtime. |
| 520 StaticResource<StringInputBuffer> string_input_buffer_; |
| 521 unibrow::Mapping<unibrow::ToUppercase, 128> to_upper_mapping_; |
| 522 unibrow::Mapping<unibrow::ToLowercase, 128> to_lower_mapping_; |
| 523 StringInputBuffer string_input_buffer_compare_bufx_; |
| 524 StringInputBuffer string_input_buffer_compare_bufy_; |
| 525 StringInputBuffer string_locale_compare_buf1_; |
| 526 StringInputBuffer string_locale_compare_buf2_; |
| 527 int smi_lexicographic_compare_x_elms_[10]; |
| 528 int smi_lexicographic_compare_y_elms_[10]; |
| 529 |
| 530 friend class Isolate; |
| 531 friend class Runtime; |
| 532 |
| 533 DISALLOW_COPY_AND_ASSIGN(RuntimeState); |
| 534 }; |
| 535 |
| 536 |
485 class Runtime : public AllStatic { | 537 class Runtime : public AllStatic { |
486 public: | 538 public: |
487 enum FunctionId { | 539 enum FunctionId { |
488 #define F(name, nargs, ressize) k##name, | 540 #define F(name, nargs, ressize) k##name, |
489 RUNTIME_FUNCTION_LIST(F) | 541 RUNTIME_FUNCTION_LIST(F) |
490 #undef F | 542 #undef F |
491 #define F(name, nargs, ressize) kInline##name, | 543 #define F(name, nargs, ressize) kInline##name, |
492 INLINE_FUNCTION_LIST(F) | 544 INLINE_FUNCTION_LIST(F) |
493 INLINE_RUNTIME_FUNCTION_LIST(F) | 545 INLINE_RUNTIME_FUNCTION_LIST(F) |
494 #undef F | 546 #undef F |
(...skipping 23 matching lines...) Expand all Loading... |
518 int result_size; | 570 int result_size; |
519 }; | 571 }; |
520 | 572 |
521 static const int kNotFound = -1; | 573 static const int kNotFound = -1; |
522 | 574 |
523 // Add symbols for all the intrinsic function names to a StringDictionary. | 575 // Add symbols for all the intrinsic function names to a StringDictionary. |
524 // Returns failure if an allocation fails. In this case, it must be | 576 // Returns failure if an allocation fails. In this case, it must be |
525 // retried with a new, empty StringDictionary, not with the same one. | 577 // retried with a new, empty StringDictionary, not with the same one. |
526 // Alternatively, heap initialization can be completely restarted. | 578 // Alternatively, heap initialization can be completely restarted. |
527 MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames( | 579 MUST_USE_RESULT static MaybeObject* InitializeIntrinsicFunctionNames( |
528 Object* dictionary); | 580 Heap* heap, Object* dictionary); |
529 | 581 |
530 // Get the intrinsic function with the given name, which must be a symbol. | 582 // Get the intrinsic function with the given name, which must be a symbol. |
531 static Function* FunctionForSymbol(Handle<String> name); | 583 static const Function* FunctionForSymbol(Handle<String> name); |
532 | 584 |
533 // Get the intrinsic function with the given FunctionId. | 585 // Get the intrinsic function with the given FunctionId. |
534 static Function* FunctionForId(FunctionId id); | 586 static const Function* FunctionForId(FunctionId id); |
535 | 587 |
536 // General-purpose helper functions for runtime system. | 588 // General-purpose helper functions for runtime system. |
537 static int StringMatch(Handle<String> sub, Handle<String> pat, int index); | 589 static int StringMatch(Isolate* isolate, |
| 590 Handle<String> sub, |
| 591 Handle<String> pat, |
| 592 int index); |
538 | 593 |
539 static bool IsUpperCaseChar(uint16_t ch); | 594 static bool IsUpperCaseChar(RuntimeState* runtime_state, uint16_t ch); |
540 | 595 |
541 // TODO(1240886): The following three methods are *not* handle safe, | 596 // TODO(1240886): The following three methods are *not* handle safe, |
542 // but accept handle arguments. This seems fragile. | 597 // but accept handle arguments. This seems fragile. |
543 | 598 |
544 // Support getting the characters in a string using [] notation as | 599 // Support getting the characters in a string using [] notation as |
545 // in Firefox/SpiderMonkey, Safari and Opera. | 600 // in Firefox/SpiderMonkey, Safari and Opera. |
546 MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Handle<Object> object, | 601 MUST_USE_RESULT static MaybeObject* GetElementOrCharAt(Isolate* isolate, |
| 602 Handle<Object> object, |
547 uint32_t index); | 603 uint32_t index); |
548 MUST_USE_RESULT static MaybeObject* GetElement(Handle<Object> object, | 604 MUST_USE_RESULT static MaybeObject* GetElement(Handle<Object> object, |
549 uint32_t index); | 605 uint32_t index); |
550 | 606 |
551 MUST_USE_RESULT static MaybeObject* SetObjectProperty( | 607 MUST_USE_RESULT static MaybeObject* SetObjectProperty( |
| 608 Isolate* isolate, |
552 Handle<Object> object, | 609 Handle<Object> object, |
553 Handle<Object> key, | 610 Handle<Object> key, |
554 Handle<Object> value, | 611 Handle<Object> value, |
555 PropertyAttributes attr, | 612 PropertyAttributes attr, |
556 StrictModeFlag strict_mode); | 613 StrictModeFlag strict_mode); |
557 | 614 |
558 MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty( | 615 MUST_USE_RESULT static MaybeObject* ForceSetObjectProperty( |
| 616 Isolate* isolate, |
559 Handle<JSObject> object, | 617 Handle<JSObject> object, |
560 Handle<Object> key, | 618 Handle<Object> key, |
561 Handle<Object> value, | 619 Handle<Object> value, |
562 PropertyAttributes attr); | 620 PropertyAttributes attr); |
563 | 621 |
564 MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty( | 622 MUST_USE_RESULT static MaybeObject* ForceDeleteObjectProperty( |
| 623 Isolate* isolate, |
565 Handle<JSObject> object, | 624 Handle<JSObject> object, |
566 Handle<Object> key); | 625 Handle<Object> key); |
567 | 626 |
568 MUST_USE_RESULT static MaybeObject* GetObjectProperty(Handle<Object> object, | 627 MUST_USE_RESULT static MaybeObject* GetObjectProperty( |
569 Handle<Object> key); | 628 Isolate* isolate, |
| 629 Handle<Object> object, |
| 630 Handle<Object> key); |
570 | 631 |
571 // This function is used in FunctionNameUsing* tests. | 632 // This function is used in FunctionNameUsing* tests. |
572 static Object* FindSharedFunctionInfoInScript(Handle<Script> script, | 633 static Object* FindSharedFunctionInfoInScript(Isolate* isolate, |
| 634 Handle<Script> script, |
573 int position); | 635 int position); |
574 | 636 |
575 // Helper functions used stubs. | 637 // Helper functions used stubs. |
576 static void PerformGC(Object* result); | 638 static void PerformGC(Object* result); |
577 }; | 639 }; |
578 | 640 |
579 | |
580 } } // namespace v8::internal | 641 } } // namespace v8::internal |
581 | 642 |
582 #endif // V8_RUNTIME_H_ | 643 #endif // V8_RUNTIME_H_ |
OLD | NEW |