Skip to content

Commit b5a19c1

Browse files
Rework the way we handle the fact that the ARM simulator uses a
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
1 parent ec7034e commit b5a19c1

13 files changed

+218
-114
lines changed

include/v8.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ class Data;
129129

130130
namespace internal {
131131

132-
class Object;
133132
class Arguments;
133+
class Object;
134+
class Top;
134135

135136
}
136137

@@ -2532,15 +2533,16 @@ class V8EXPORT TryCatch {
25322533
*/
25332534
void SetCaptureMessage(bool value);
25342535

2535-
public:
2536-
TryCatch* next_;
2536+
private:
2537+
void* next_;
25372538
void* exception_;
25382539
void* message_;
25392540
bool is_verbose_ : 1;
25402541
bool can_continue_ : 1;
25412542
bool capture_message_ : 1;
25422543
bool rethrow_ : 1;
2543-
void* js_handler_;
2544+
2545+
friend class v8::internal::Top;
25442546
};
25452547

25462548

src/api.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -1191,14 +1191,13 @@ void Script::SetData(v8::Handle<Value> data) {
11911191

11921192

11931193
v8::TryCatch::TryCatch()
1194-
: next_(i::Top::try_catch_handler()),
1194+
: next_(i::Top::try_catch_handler_address()),
11951195
exception_(i::Heap::the_hole_value()),
11961196
message_(i::Smi::FromInt(0)),
11971197
is_verbose_(false),
11981198
can_continue_(true),
11991199
capture_message_(true),
1200-
rethrow_(false),
1201-
js_handler_(NULL) {
1200+
rethrow_(false) {
12021201
i::Top::RegisterTryCatchHandler(this);
12031202
}
12041203

src/arm/simulator-arm.cc

+19
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,25 @@ int32_t Simulator::Call(byte* entry, int argument_count, ...) {
19241924
return result;
19251925
}
19261926

1927+
1928+
uintptr_t Simulator::PushAddress(uintptr_t address) {
1929+
int new_sp = get_register(sp) - sizeof(uintptr_t);
1930+
uintptr_t* stack_slot = reinterpret_cast<uintptr_t*>(new_sp);
1931+
*stack_slot = address;
1932+
set_register(sp, new_sp);
1933+
return new_sp;
1934+
}
1935+
1936+
1937+
uintptr_t Simulator::PopAddress() {
1938+
int current_sp = get_register(sp);
1939+
uintptr_t* stack_slot = reinterpret_cast<uintptr_t*>(current_sp);
1940+
uintptr_t address = *stack_slot;
1941+
set_register(sp, current_sp + sizeof(uintptr_t));
1942+
return address;
1943+
}
1944+
1945+
19271946
} } // namespace assembler::arm
19281947

19291948
#endif // !defined(__arm__)

src/arm/simulator-arm.h

+33-3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ class SimulatorStack : public v8::internal::AllStatic {
5252
static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) {
5353
return c_limit;
5454
}
55+
56+
static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) {
57+
return try_catch_address;
58+
}
59+
60+
static inline void UnregisterCTryCatch() { }
5561
};
5662

5763

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

69+
#define TRY_CATCH_FROM_ADDRESS(try_catch_address) \
70+
reinterpret_cast<TryCatch*>(try_catch_address)
71+
72+
6373
#else // defined(__arm__)
6474

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

86+
#define TRY_CATCH_FROM_ADDRESS(try_catch_address) \
87+
try_catch_address == NULL ? \
88+
NULL : *(reinterpret_cast<TryCatch**>(try_catch_address))
89+
90+
7691
#include "constants-arm.h"
7792

7893

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

142+
// Push an address onto the JS stack.
143+
uintptr_t PushAddress(uintptr_t address);
144+
145+
// Pop an address from the JS stack.
146+
uintptr_t PopAddress();
147+
127148
private:
128149
enum special_values {
129150
// Known bad pc value to ensure that the simulator does not execute
@@ -198,20 +219,20 @@ class Simulator {
198219
void SetFpResult(const double& result);
199220
void TrashCallerSaveRegisters();
200221

201-
// architecture state
222+
// Architecture state.
202223
int32_t registers_[16];
203224
bool n_flag_;
204225
bool z_flag_;
205226
bool c_flag_;
206227
bool v_flag_;
207228

208-
// simulator support
229+
// Simulator support.
209230
char* stack_;
210231
bool pc_modified_;
211232
int icount_;
212233
static bool initialized_;
213234

214-
// registered breakpoints
235+
// Registered breakpoints.
215236
Instr* break_pc_;
216237
instr_t break_instr_;
217238
};
@@ -229,6 +250,15 @@ class SimulatorStack : public v8::internal::AllStatic {
229250
static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) {
230251
return assembler::arm::Simulator::current()->StackLimit();
231252
}
253+
254+
static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) {
255+
assembler::arm::Simulator* sim = assembler::arm::Simulator::current();
256+
return sim->PushAddress(try_catch_address);
257+
}
258+
259+
static inline void UnregisterCTryCatch() {
260+
assembler::arm::Simulator::current()->PopAddress();
261+
}
232262
};
233263

234264

src/execution.cc

+1-11
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,8 @@
3131

3232
#include "api.h"
3333
#include "codegen-inl.h"
34-
35-
#if V8_TARGET_ARCH_IA32
36-
#include "ia32/simulator-ia32.h"
37-
#elif V8_TARGET_ARCH_X64
38-
#include "x64/simulator-x64.h"
39-
#elif V8_TARGET_ARCH_ARM
40-
#include "arm/simulator-arm.h"
41-
#else
42-
#error Unsupported target architecture.
43-
#endif
44-
4534
#include "debug.h"
35+
#include "simulator.h"
4636
#include "v8threads.h"
4737

4838
namespace v8 {

src/ia32/simulator-ia32.h

+9
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,20 @@ class SimulatorStack : public v8::internal::AllStatic {
4343
static inline uintptr_t JsLimitFromCLimit(uintptr_t c_limit) {
4444
return c_limit;
4545
}
46+
47+
static inline uintptr_t RegisterCTryCatch(uintptr_t try_catch_address) {
48+
return try_catch_address;
49+
}
50+
51+
static inline void UnregisterCTryCatch() { }
4652
};
4753

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

59+
#define TRY_CATCH_FROM_ADDRESS(try_catch_address) \
60+
reinterpret_cast<TryCatch*>(try_catch_address)
61+
5362
#endif // V8_IA32_SIMULATOR_IA32_H_

src/regexp-macro-assembler.cc

+1-7
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@
3030
#include "assembler.h"
3131
#include "regexp-stack.h"
3232
#include "regexp-macro-assembler.h"
33-
#if V8_TARGET_ARCH_ARM
34-
#include "arm/simulator-arm.h"
35-
#elif V8_TARGET_ARCH_IA32
36-
#include "ia32/simulator-ia32.h"
37-
#elif V8_TARGET_ARCH_X64
38-
#include "x64/simulator-x64.h"
39-
#endif
33+
#include "simulator.h"
4034

4135
namespace v8 {
4236
namespace internal {

src/simulator.h

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2009 the V8 project authors. All rights reserved.
2+
// Redistribution and use in source and binary forms, with or without
3+
// modification, are permitted provided that the following conditions are
4+
// met:
5+
//
6+
// * Redistributions of source code must retain the above copyright
7+
// notice, this list of conditions and the following disclaimer.
8+
// * Redistributions in binary form must reproduce the above
9+
// copyright notice, this list of conditions and the following
10+
// disclaimer in the documentation and/or other materials provided
11+
// with the distribution.
12+
// * Neither the name of Google Inc. nor the names of its
13+
// contributors may be used to endorse or promote products derived
14+
// from this software without specific prior written permission.
15+
//
16+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27+
28+
#ifndef V8_SIMULATOR_H_
29+
#define V8_SIMULATOR_H_
30+
31+
#if V8_TARGET_ARCH_IA32
32+
#include "ia32/simulator-ia32.h"
33+
#elif V8_TARGET_ARCH_X64
34+
#include "x64/simulator-x64.h"
35+
#elif V8_TARGET_ARCH_ARM
36+
#include "arm/simulator-arm.h"
37+
#else
38+
#error Unsupported target architecture.
39+
#endif
40+
41+
#endif // V8_SIMULATOR_H_

0 commit comments

Comments
 (0)