Skip to content

Commit

Permalink
Rework the way we handle the fact that the ARM simulator uses a
Browse files Browse the repository at this point in the history
separate JS stack.

In exception handling, we need to be able to compare addresses into
the JavaScript portion of the stack with the address of a C++ handler
on the stack.  Since the stacks are separate on the simulator, we need
a JavaScript stack address corresponding to a C++ try catch handler in
order to perform valid address comparisons.

On the simulator, we now link the C++ try catch handlers indirectly
through the JS stack and use the JS stack indirection address for
comparisons.

      JS                    C++
                           
                           handler
 [C++ address]   <------    next_
                \
                 \
                  \---->   handler
 [C++ address]   <------    next_


On actual hardware the C++ try catch handlers continue to be directly
linked.

BUG=http://code.google.com/p/v8/issues/detail?id=271
Review URL: http://codereview.chromium.org/360004

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3228 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
  • Loading branch information
[email protected] committed Nov 5, 2009
1 parent ec7034e commit b5a19c1
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 114 deletions.
10 changes: 6 additions & 4 deletions include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ class Data;

namespace internal {

class Object;
class Arguments;
class Object;
class Top;

}

Expand Down Expand Up @@ -2532,15 +2533,16 @@ class V8EXPORT TryCatch {
*/
void SetCaptureMessage(bool value);

public:
TryCatch* next_;
private:
void* next_;
void* exception_;
void* message_;
bool is_verbose_ : 1;
bool can_continue_ : 1;
bool capture_message_ : 1;
bool rethrow_ : 1;
void* js_handler_;

friend class v8::internal::Top;
};


Expand Down
5 changes: 2 additions & 3 deletions src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1191,14 +1191,13 @@ void Script::SetData(v8::Handle<Value> data) {


v8::TryCatch::TryCatch()
: next_(i::Top::try_catch_handler()),
: next_(i::Top::try_catch_handler_address()),
exception_(i::Heap::the_hole_value()),
message_(i::Smi::FromInt(0)),
is_verbose_(false),
can_continue_(true),
capture_message_(true),
rethrow_(false),
js_handler_(NULL) {
rethrow_(false) {
i::Top::RegisterTryCatchHandler(this);
}

Expand Down
19 changes: 19 additions & 0 deletions src/arm/simulator-arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1924,6 +1924,25 @@ int32_t Simulator::Call(byte* entry, int argument_count, ...) {
return result;
}


uintptr_t Simulator::PushAddress(uintptr_t address) {
int new_sp = get_register(sp) - sizeof(uintptr_t);
uintptr_t* stack_slot = reinterpret_cast<uintptr_t*>(new_sp);
*stack_slot = address;
set_register(sp, new_sp);
return new_sp;
}


uintptr_t Simulator::PopAddress() {
int current_sp = get_register(sp);
uintptr_t* stack_slot = reinterpret_cast<uintptr_t*>(current_sp);
uintptr_t address = *stack_slot;
set_register(sp, current_sp + sizeof(uintptr_t));
return address;
}


} } // namespace assembler::arm

#endif // !defined(__arm__)
36 changes: 33 additions & 3 deletions src/arm/simulator-arm.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ class SimulatorStack : public v8::internal::AllStatic {
static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) {
return c_limit;
}

static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) {
return try_catch_address;
}

static inline void UnregisterCTryCatch() { }
};


Expand All @@ -60,6 +66,10 @@ class SimulatorStack : public v8::internal::AllStatic {
#define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6) \
entry(p0, p1, p2, p3, p4, p5, p6)

#define TRY_CATCH_FROM_ADDRESS(try_catch_address) \
reinterpret_cast<TryCatch*>(try_catch_address)


#else // defined(__arm__)

// When running with the simulator transition into simulated execution at this
Expand All @@ -73,6 +83,11 @@ class SimulatorStack : public v8::internal::AllStatic {
assembler::arm::Simulator::current()->Call( \
FUNCTION_ADDR(entry), 7, p0, p1, p2, p3, p4, p5, p6)

#define TRY_CATCH_FROM_ADDRESS(try_catch_address) \
try_catch_address == NULL ? \
NULL : *(reinterpret_cast<TryCatch**>(try_catch_address))


#include "constants-arm.h"


Expand Down Expand Up @@ -124,6 +139,12 @@ class Simulator {
// which sets up the simulator state and grabs the result on return.
int32_t Call(byte* entry, int argument_count, ...);

// Push an address onto the JS stack.
uintptr_t PushAddress(uintptr_t address);

// Pop an address from the JS stack.
uintptr_t PopAddress();

private:
enum special_values {
// Known bad pc value to ensure that the simulator does not execute
Expand Down Expand Up @@ -198,20 +219,20 @@ class Simulator {
void SetFpResult(const double& result);
void TrashCallerSaveRegisters();

// architecture state
// Architecture state.
int32_t registers_[16];
bool n_flag_;
bool z_flag_;
bool c_flag_;
bool v_flag_;

// simulator support
// Simulator support.
char* stack_;
bool pc_modified_;
int icount_;
static bool initialized_;

// registered breakpoints
// Registered breakpoints.
Instr* break_pc_;
instr_t break_instr_;
};
Expand All @@ -229,6 +250,15 @@ class SimulatorStack : public v8::internal::AllStatic {
static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) {
return assembler::arm::Simulator::current()->StackLimit();
}

static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) {
assembler::arm::Simulator* sim = assembler::arm::Simulator::current();
return sim->PushAddress(try_catch_address);
}

static inline void UnregisterCTryCatch() {
assembler::arm::Simulator::current()->PopAddress();
}
};


Expand Down
12 changes: 1 addition & 11 deletions src/execution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,8 @@

#include "api.h"
#include "codegen-inl.h"

#if V8_TARGET_ARCH_IA32
#include "ia32/simulator-ia32.h"
#elif V8_TARGET_ARCH_X64
#include "x64/simulator-x64.h"
#elif V8_TARGET_ARCH_ARM
#include "arm/simulator-arm.h"
#else
#error Unsupported target architecture.
#endif

#include "debug.h"
#include "simulator.h"
#include "v8threads.h"

namespace v8 {
Expand Down
9 changes: 9 additions & 0 deletions src/ia32/simulator-ia32.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,20 @@ class SimulatorStack : public v8::internal::AllStatic {
static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) {
return c_limit;
}

static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) {
return try_catch_address;
}

static inline void UnregisterCTryCatch() { }
};

// Call the generated regexp code directly. The entry function pointer should
// expect seven int/pointer sized arguments and return an int.
#define CALL_GENERATED_REGEXP_CODE(entry, p0, p1, p2, p3, p4, p5, p6) \
entry(p0, p1, p2, p3, p4, p5, p6)

#define TRY_CATCH_FROM_ADDRESS(try_catch_address) \
reinterpret_cast<TryCatch*>(try_catch_address)

#endif // V8_IA32_SIMULATOR_IA32_H_
8 changes: 1 addition & 7 deletions src/regexp-macro-assembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@
#include "assembler.h"
#include "regexp-stack.h"
#include "regexp-macro-assembler.h"
#if V8_TARGET_ARCH_ARM
#include "arm/simulator-arm.h"
#elif V8_TARGET_ARCH_IA32
#include "ia32/simulator-ia32.h"
#elif V8_TARGET_ARCH_X64
#include "x64/simulator-x64.h"
#endif
#include "simulator.h"

namespace v8 {
namespace internal {
Expand Down
41 changes: 41 additions & 0 deletions src/simulator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef V8_SIMULATOR_H_
#define V8_SIMULATOR_H_

#if V8_TARGET_ARCH_IA32
#include "ia32/simulator-ia32.h"
#elif V8_TARGET_ARCH_X64
#include "x64/simulator-x64.h"
#elif V8_TARGET_ARCH_ARM
#include "arm/simulator-arm.h"
#else
#error Unsupported target architecture.
#endif

#endif // V8_SIMULATOR_H_
Loading

0 comments on commit b5a19c1

Please sign in to comment.