Reviewers: Mads Ager, Vitaly Repeshko,
Description:
Move SafeStackFrameIterator::active_count_ into an isolate.
[email protected],[email protected]
BUG=none
TEST=none
Please review this at http://codereview.chromium.org/6771047/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/frames.h
M src/frames.cc
M src/isolate.h
M src/top.cc
Index: src/frames.cc
diff --git a/src/frames.cc b/src/frames.cc
index
79aa2507fba0c31230192a6bb6754a3d5599ce95..b817d9ab82ecd8c86818e4dbb74911f815ac6ae2
100644
--- a/src/frames.cc
+++ b/src/frames.cc
@@ -39,9 +39,6 @@
namespace v8 {
namespace internal {
-
-int SafeStackFrameIterator::active_count_ = 0;
-
// Iterator that supports traversing the stack handlers of a
// particular frame. Needs to know the top of the handler chain.
class StackHandlerIterator BASE_EMBEDDED {
@@ -221,10 +218,22 @@ bool
SafeStackFrameIterator::ExitFrameValidator::IsValidFP(Address fp) {
}
+SafeStackFrameIterator::ActiveCountMaintainer::ActiveCountMaintainer(
+ Isolate* isolate)
+ : isolate_(isolate) {
+ Isolate::inc_safe_stack_iterator_counter(isolate_->thread_local_top());
+}
+
+
+SafeStackFrameIterator::ActiveCountMaintainer::~ActiveCountMaintainer() {
+ Isolate::dec_safe_stack_iterator_counter(isolate_->thread_local_top());
+}
+
+
SafeStackFrameIterator::SafeStackFrameIterator(
Isolate* isolate,
Address fp, Address sp, Address low_bound, Address high_bound) :
- maintainer_(),
+ maintainer_(isolate),
stack_validator_(low_bound, high_bound),
is_valid_top_(IsValidTop(isolate, low_bound, high_bound)),
is_valid_fp_(IsWithinBounds(low_bound, high_bound, fp)),
@@ -233,6 +242,10 @@ SafeStackFrameIterator::SafeStackFrameIterator(
iterator_(isolate, is_valid_top_, is_valid_fp_ ? fp : NULL, sp) {
}
+bool SafeStackFrameIterator::is_active(Isolate* isolate) {
+ return Isolate::safe_stack_iterator_counter(isolate->thread_local_top())
0;
+}
+
bool SafeStackFrameIterator::IsValidTop(Isolate* isolate,
Address low_bound, Address
high_bound) {
@@ -392,7 +405,8 @@ StackFrame::Type StackFrame::ComputeType(State* state) {
// frames as normal JavaScript frames to avoid having to look
// into the heap to determine the state. This is safe as long
// as nobody tries to GC...
- if (SafeStackFrameIterator::is_active()) return JAVA_SCRIPT;
+ if (SafeStackFrameIterator::is_active(Isolate::Current()))
+ return JAVA_SCRIPT;
Code::Kind kind = GetContainingCode(Isolate::Current(),
*(state->pc_address))->kind();
ASSERT(kind == Code::FUNCTION || kind == Code::OPTIMIZED_FUNCTION);
@@ -539,7 +553,7 @@ void OptimizedFrame::Iterate(ObjectVisitor* v) const {
// Make sure that we're not doing "safe" stack frame iteration. We cannot
// possibly find pointers in optimized frames in that state.
- ASSERT(!SafeStackFrameIterator::is_active());
+ ASSERT(!SafeStackFrameIterator::is_active(Isolate::Current()));
// Compute the safepoint information.
unsigned stack_slots = 0;
@@ -640,7 +654,7 @@ Code* JavaScriptFrame::unchecked_code() const {
Address JavaScriptFrame::GetCallerStackPointer() const {
int arguments;
- if (SafeStackFrameIterator::is_active() ||
+ if (SafeStackFrameIterator::is_active(Isolate::Current()) ||
HEAP->gc_state() != Heap::NOT_IN_GC) {
// If the we are currently iterating the safe stack the
// arguments for frames are traversed as if they were
Index: src/frames.h
diff --git a/src/frames.h b/src/frames.h
index
bee95ccbf1d2582c448a344280429cc6e07f7bdf..e95229800e5919f365edd50566f590512c8cc0bc
100644
--- a/src/frames.h
+++ b/src/frames.h
@@ -739,7 +739,7 @@ class SafeStackFrameIterator BASE_EMBEDDED {
void Advance();
void Reset();
- static bool is_active() { return active_count_ > 0; }
+ static bool is_active(Isolate* isolate);
static bool IsWithinBounds(
Address low_bound, Address high_bound, Address addr) {
@@ -786,13 +786,13 @@ class SafeStackFrameIterator BASE_EMBEDDED {
// heap objects.
class ActiveCountMaintainer BASE_EMBEDDED {
public:
- ActiveCountMaintainer() { active_count_++; }
- ~ActiveCountMaintainer() { active_count_--; }
+ explicit ActiveCountMaintainer(Isolate* isolate);
+ ~ActiveCountMaintainer();
+ private:
+ Isolate* isolate_;
};
ActiveCountMaintainer maintainer_;
- // TODO(isolates): this is dangerous.
- static int active_count_;
StackAddressValidator stack_validator_;
const bool is_valid_top_;
const bool is_valid_fp_;
Index: src/isolate.h
diff --git a/src/isolate.h b/src/isolate.h
index
a9962c3f9fd636d45ddcfb1e51890a727dd95b7e..ab90eff8bb7860e85d4c894a1007aeba91bd17ea
100644
--- a/src/isolate.h
+++ b/src/isolate.h
@@ -195,6 +195,7 @@ class ThreadLocalTop BASE_EMBEDDED {
// Stack.
Address c_entry_fp_; // the frame pointer of the top c entry frame
Address handler_; // try-blocks are chained through the stack
+ int safe_stack_iterator_counter_;
#ifdef USE_SIMULATOR
#if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_MIPS)
@@ -547,6 +548,15 @@ class Isolate {
return thread->c_entry_fp_;
}
static Address handler(ThreadLocalTop* thread) { return
thread->handler_; }
+ static int safe_stack_iterator_counter(ThreadLocalTop* thread) {
+ return thread->safe_stack_iterator_counter_;
+ }
+ static void inc_safe_stack_iterator_counter(ThreadLocalTop* thread) {
+ ++thread->safe_stack_iterator_counter_;
+ }
+ static void dec_safe_stack_iterator_counter(ThreadLocalTop* thread) {
+ --thread->safe_stack_iterator_counter_;
+ }
inline Address* c_entry_fp_address() {
return &thread_local_top_.c_entry_fp_;
Index: src/top.cc
diff --git a/src/top.cc b/src/top.cc
index
ff29cad46466297cdc775eb1b1be84298902fef7..b69ed138a9f3d17cd4be4f958eb8c815743ea6a2
100644
--- a/src/top.cc
+++ b/src/top.cc
@@ -51,6 +51,7 @@ v8::TryCatch* ThreadLocalTop::TryCatchHandler() {
void ThreadLocalTop::Initialize() {
c_entry_fp_ = 0;
handler_ = 0;
+ safe_stack_iterator_counter_ = 0;
#ifdef USE_SIMULATOR
#ifdef V8_TARGET_ARCH_ARM
simulator_ = Simulator::current(Isolate::Current());
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev