| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 inner_pointer_to_code_cache_(NULL), | 1466 inner_pointer_to_code_cache_(NULL), |
| 1467 write_input_buffer_(NULL), | 1467 write_input_buffer_(NULL), |
| 1468 global_handles_(NULL), | 1468 global_handles_(NULL), |
| 1469 context_switcher_(NULL), | 1469 context_switcher_(NULL), |
| 1470 thread_manager_(NULL), | 1470 thread_manager_(NULL), |
| 1471 fp_stubs_generated_(false), | 1471 fp_stubs_generated_(false), |
| 1472 has_installed_extensions_(false), | 1472 has_installed_extensions_(false), |
| 1473 string_tracker_(NULL), | 1473 string_tracker_(NULL), |
| 1474 regexp_stack_(NULL), | 1474 regexp_stack_(NULL), |
| 1475 date_cache_(NULL), | 1475 date_cache_(NULL), |
| 1476 context_exit_happened_(false) { | 1476 context_exit_happened_(false), |
| 1477 to_delete_(false) { |
| 1477 TRACE_ISOLATE(constructor); | 1478 TRACE_ISOLATE(constructor); |
| 1478 | 1479 |
| 1479 memset(isolate_addresses_, 0, | 1480 memset(isolate_addresses_, 0, |
| 1480 sizeof(isolate_addresses_[0]) * (kIsolateAddressCount + 1)); | 1481 sizeof(isolate_addresses_[0]) * (kIsolateAddressCount + 1)); |
| 1481 | 1482 |
| 1482 heap_.isolate_ = this; | 1483 heap_.isolate_ = this; |
| 1483 zone_.isolate_ = this; | 1484 zone_.isolate_ = this; |
| 1484 stack_guard_.isolate_ = this; | 1485 stack_guard_.isolate_ = this; |
| 1485 | 1486 |
| 1486 // ThreadManager is initialized early to support locking an isolate | 1487 // ThreadManager is initialized early to support locking an isolate |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1515 #undef ISOLATE_INIT_EXECUTE | 1516 #undef ISOLATE_INIT_EXECUTE |
| 1516 | 1517 |
| 1517 #define ISOLATE_INIT_ARRAY_EXECUTE(type, name, length) \ | 1518 #define ISOLATE_INIT_ARRAY_EXECUTE(type, name, length) \ |
| 1518 memset(name##_, 0, sizeof(type) * length); | 1519 memset(name##_, 0, sizeof(type) * length); |
| 1519 ISOLATE_INIT_ARRAY_LIST(ISOLATE_INIT_ARRAY_EXECUTE) | 1520 ISOLATE_INIT_ARRAY_LIST(ISOLATE_INIT_ARRAY_EXECUTE) |
| 1520 #undef ISOLATE_INIT_ARRAY_EXECUTE | 1521 #undef ISOLATE_INIT_ARRAY_EXECUTE |
| 1521 } | 1522 } |
| 1522 | 1523 |
| 1523 void Isolate::TearDown() { | 1524 void Isolate::TearDown() { |
| 1524 TRACE_ISOLATE(tear_down); | 1525 TRACE_ISOLATE(tear_down); |
| 1526 ASSERT(!FLAG_concurrent_crankshaft || |
| 1527 thread_manager()->IsLockedByCurrentThread()); |
| 1525 | 1528 |
| 1526 // Temporarily set this isolate as current so that various parts of | 1529 // Temporarily set this isolate as current so that various parts of |
| 1527 // the isolate can access it in their destructors without having a | 1530 // the isolate can access it in their destructors without having a |
| 1528 // direct pointer. We don't use Enter/Exit here to avoid | 1531 // direct pointer. We don't use Enter/Exit here to avoid |
| 1529 // initializing the thread data. | 1532 // initializing the thread data. |
| 1530 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData(); | 1533 PerIsolateThreadData* saved_data = CurrentPerIsolateThreadData(); |
| 1531 Isolate* saved_isolate = UncheckedCurrent(); | 1534 Isolate* saved_isolate = UncheckedCurrent(); |
| 1532 SetIsolateThreadLocals(this, NULL); | 1535 SetIsolateThreadLocals(this, NULL); |
| 1533 | 1536 |
| 1534 Deinit(); | 1537 Deinit(); |
| 1535 | 1538 |
| 1536 { ScopedLock lock(process_wide_mutex_); | 1539 { ScopedLock lock(process_wide_mutex_); |
| 1537 thread_data_table_->RemoveAllThreads(this); | 1540 thread_data_table_->RemoveAllThreads(this); |
| 1538 } | 1541 } |
| 1539 | 1542 |
| 1540 if (!IsDefaultIsolate()) { | 1543 if (!IsDefaultIsolate() && !FLAG_concurrent_crankshaft) { |
| 1541 delete this; | 1544 delete this; |
| 1542 } | 1545 } |
| 1543 | 1546 |
| 1547 if (FLAG_concurrent_crankshaft) |
| 1548 to_delete_ = true; |
| 1549 |
| 1544 // Restore the previous current isolate. | 1550 // Restore the previous current isolate. |
| 1545 SetIsolateThreadLocals(saved_isolate, saved_data); | 1551 SetIsolateThreadLocals(saved_isolate, saved_data); |
| 1546 } | 1552 } |
| 1547 | 1553 |
| 1548 | 1554 |
| 1549 void Isolate::Deinit() { | 1555 void Isolate::Deinit() { |
| 1550 if (state_ == INITIALIZED) { | 1556 if (state_ == INITIALIZED) { |
| 1551 TRACE_ISOLATE(deinit); | 1557 TRACE_ISOLATE(deinit); |
| 1552 | 1558 |
| 1553 if (FLAG_hydrogen_stats) HStatistics::Instance()->Print(); | 1559 if (FLAG_hydrogen_stats) HStatistics::Instance()->Print(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 void Isolate::SetIsolateThreadLocals(Isolate* isolate, | 1594 void Isolate::SetIsolateThreadLocals(Isolate* isolate, |
| 1589 PerIsolateThreadData* data) { | 1595 PerIsolateThreadData* data) { |
| 1590 Thread::SetThreadLocal(isolate_key_, isolate); | 1596 Thread::SetThreadLocal(isolate_key_, isolate); |
| 1591 Thread::SetThreadLocal(per_isolate_thread_data_key_, data); | 1597 Thread::SetThreadLocal(per_isolate_thread_data_key_, data); |
| 1592 } | 1598 } |
| 1593 | 1599 |
| 1594 | 1600 |
| 1595 Isolate::~Isolate() { | 1601 Isolate::~Isolate() { |
| 1596 TRACE_ISOLATE(destructor); | 1602 TRACE_ISOLATE(destructor); |
| 1597 | 1603 |
| 1604 ASSERT(!FLAG_concurrent_crankshaft || to_delete()); |
| 1605 |
| 1598 // Has to be called while counters_ are still alive. | 1606 // Has to be called while counters_ are still alive. |
| 1599 zone_.DeleteKeptSegment(); | 1607 zone_.DeleteKeptSegment(); |
| 1600 | 1608 |
| 1601 delete[] assembler_spare_buffer_; | 1609 delete[] assembler_spare_buffer_; |
| 1602 assembler_spare_buffer_ = NULL; | 1610 assembler_spare_buffer_ = NULL; |
| 1603 | 1611 |
| 1604 delete unicode_cache_; | 1612 delete unicode_cache_; |
| 1605 unicode_cache_ = NULL; | 1613 unicode_cache_ = NULL; |
| 1606 | 1614 |
| 1607 delete date_cache_; | 1615 delete date_cache_; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1874 // v8::V8::SetAddHistogramSampleFunction calls. | 1882 // v8::V8::SetAddHistogramSampleFunction calls. |
| 1875 StatsTable* Isolate::stats_table() { | 1883 StatsTable* Isolate::stats_table() { |
| 1876 if (stats_table_ == NULL) { | 1884 if (stats_table_ == NULL) { |
| 1877 stats_table_ = new StatsTable; | 1885 stats_table_ = new StatsTable; |
| 1878 } | 1886 } |
| 1879 return stats_table_; | 1887 return stats_table_; |
| 1880 } | 1888 } |
| 1881 | 1889 |
| 1882 | 1890 |
| 1883 void Isolate::Enter() { | 1891 void Isolate::Enter() { |
| 1892 if (FLAG_concurrent_crankshaft) { |
| 1893 bool to_lock = !thread_manager()->IsLockedByCurrentThread(); |
| 1894 if (to_lock) |
| 1895 thread_manager()->Lock(); |
| 1896 lock_history_.Add(to_lock); |
| 1897 } |
| 1898 |
| 1884 Isolate* current_isolate = NULL; | 1899 Isolate* current_isolate = NULL; |
| 1885 PerIsolateThreadData* current_data = CurrentPerIsolateThreadData(); | 1900 PerIsolateThreadData* current_data = CurrentPerIsolateThreadData(); |
| 1886 if (current_data != NULL) { | 1901 if (current_data != NULL) { |
| 1887 current_isolate = current_data->isolate_; | 1902 current_isolate = current_data->isolate_; |
| 1888 ASSERT(current_isolate != NULL); | 1903 ASSERT(current_isolate != NULL); |
| 1889 if (current_isolate == this) { | 1904 if (current_isolate == this) { |
| 1890 ASSERT(Current() == this); | 1905 ASSERT(Current() == this); |
| 1891 ASSERT(entry_stack_ != NULL); | 1906 ASSERT(entry_stack_ != NULL); |
| 1892 ASSERT(entry_stack_->previous_thread_data == NULL || | 1907 ASSERT(entry_stack_->previous_thread_data == NULL || |
| 1893 entry_stack_->previous_thread_data->thread_id().Equals( | 1908 entry_stack_->previous_thread_data->thread_id().Equals( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1917 entry_stack_); | 1932 entry_stack_); |
| 1918 entry_stack_ = item; | 1933 entry_stack_ = item; |
| 1919 | 1934 |
| 1920 SetIsolateThreadLocals(this, data); | 1935 SetIsolateThreadLocals(this, data); |
| 1921 | 1936 |
| 1922 // In case it's the first time some thread enters the isolate. | 1937 // In case it's the first time some thread enters the isolate. |
| 1923 set_thread_id(data->thread_id()); | 1938 set_thread_id(data->thread_id()); |
| 1924 } | 1939 } |
| 1925 | 1940 |
| 1926 | 1941 |
| 1927 void Isolate::Exit() { | 1942 void Isolate::Exit(bool auto_unlock) { |
| 1928 ASSERT(entry_stack_ != NULL); | 1943 ASSERT(entry_stack_ != NULL); |
| 1929 ASSERT(entry_stack_->previous_thread_data == NULL || | 1944 ASSERT(entry_stack_->previous_thread_data == NULL || |
| 1930 entry_stack_->previous_thread_data->thread_id().Equals( | 1945 entry_stack_->previous_thread_data->thread_id().Equals( |
| 1931 ThreadId::Current())); | 1946 ThreadId::Current())); |
| 1932 | 1947 |
| 1933 if (--entry_stack_->entry_count > 0) return; | 1948 if (--entry_stack_->entry_count > 0) return; |
| 1934 | 1949 |
| 1935 ASSERT(CurrentPerIsolateThreadData() != NULL); | 1950 ASSERT(CurrentPerIsolateThreadData() != NULL); |
| 1936 ASSERT(CurrentPerIsolateThreadData()->isolate_ == this); | 1951 ASSERT(CurrentPerIsolateThreadData()->isolate_ == this); |
| 1937 | 1952 |
| 1938 // Pop the stack. | 1953 // Pop the stack. |
| 1939 EntryStackItem* item = entry_stack_; | 1954 EntryStackItem* item = entry_stack_; |
| 1940 entry_stack_ = item->previous_item; | 1955 entry_stack_ = item->previous_item; |
| 1941 | 1956 |
| 1942 PerIsolateThreadData* previous_thread_data = item->previous_thread_data; | 1957 PerIsolateThreadData* previous_thread_data = item->previous_thread_data; |
| 1943 Isolate* previous_isolate = item->previous_isolate; | 1958 Isolate* previous_isolate = item->previous_isolate; |
| 1944 | 1959 |
| 1945 delete item; | 1960 delete item; |
| 1946 | 1961 |
| 1962 if (FLAG_concurrent_crankshaft) { |
| 1963 if (lock_history_.RemoveLast() && auto_unlock) |
| 1964 thread_manager()->Unlock(); |
| 1965 } |
| 1966 |
| 1947 // Reinit the current thread for the isolate it was running before this one. | 1967 // Reinit the current thread for the isolate it was running before this one. |
| 1948 SetIsolateThreadLocals(previous_isolate, previous_thread_data); | 1968 SetIsolateThreadLocals(previous_isolate, previous_thread_data); |
| 1949 } | 1969 } |
| 1950 | 1970 |
| 1951 | 1971 |
| 1952 #ifdef DEBUG | 1972 #ifdef DEBUG |
| 1953 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ | 1973 #define ISOLATE_FIELD_OFFSET(type, name, ignored) \ |
| 1954 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); | 1974 const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_); |
| 1955 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) | 1975 ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET) |
| 1956 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) | 1976 ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET) |
| 1957 #undef ISOLATE_FIELD_OFFSET | 1977 #undef ISOLATE_FIELD_OFFSET |
| 1958 #endif | 1978 #endif |
| 1959 | 1979 |
| 1960 } } // namespace v8::internal | 1980 } } // namespace v8::internal |
| OLD | NEW |