// SScanF not beeing implemented in a platform independent was through
// ::v8::internal::OS in the same way as SNPrintF is that the Windows C Run-Time
// Library does not provide vsscanf.
-#ifdef WIN32
-#define SScanF sscanf_s
-#else
#define SScanF sscanf // NOLINT
-#endif
// The Debugger class is used by the simulator while debugging simulated ARM
// code.
}
-// This is the Simulator singleton. Currently only one thread is supported by
-// V8. If we had multiple threads, then we should have a Simulator instance on
-// a per thread basis.
-static Simulator* the_sim = NULL;
+// Create one simulator per thread and keep it in thread local storage.
+static v8::internal::Thread::LocalStorageKey simulator_key =
+ v8::internal::Thread::CreateThreadLocalKey();
-
-// Get the active Simulator for the current thread. See comment above about
-// using a singleton currently.
+// Get the active Simulator for the current thread.
Simulator* Simulator::current() {
- if (the_sim == NULL) {
- the_sim = new Simulator();
+ Simulator* sim = reinterpret_cast<Simulator*>(
+ v8::internal::Thread::GetThreadLocal(simulator_key));
+ if (sim == NULL) {
+ // TODO(146): delete the simulator object when a thread goes away.
+ sim = new Simulator();
+ v8::internal::Thread::SetThreadLocal(simulator_key, sim);
}
- return the_sim;
+ return sim;
}
//
-void Simulator::execute() {
+void Simulator::Execute() {
// Get the PC to simulate. Cannot use the accessor here as we need the
// raw PC value and not the one used as input to arithmetic instructions.
int program_counter = get_pc();
}
-Object* Simulator::call(int32_t entry, int32_t p0, int32_t p1, int32_t p2,
+Object* Simulator::Call(int32_t entry, int32_t p0, int32_t p1, int32_t p2,
int32_t p3, int32_t p4) {
// Setup parameters
set_register(r0, p0);
set_register(r11, callee_saved_value);
// Start the simulation
- execute();
+ Execute();
// Check that the callee-saved registers have been preserved.
CHECK_EQ(get_register(r4), callee_saved_value);
// When running with the simulator transition into simulated execution at this
// point.
#define CALL_GENERATED_CODE(entry, p0, p1, p2, p3, p4) \
- assembler::arm::Simulator::current()->call((int32_t)entry, (int32_t)p0, \
+ assembler::arm::Simulator::current()->Call((int32_t)entry, (int32_t)p0, \
(int32_t)p1, (int32_t)p2, (int32_t)p3, (int32_t)p4)
// The simulator has its own stack. Thus it has a different stack limit from
uintptr_t StackLimit() const;
// Executes ARM instructions until the PC reaches end_sim_pc.
- void execute();
+ void Execute();
// V8 generally calls into generated code with 5 parameters. This is a
// convenience funtion, which sets up the simulator state and grabs the
// result on return.
- v8::internal::Object* call(int32_t entry, int32_t p0, int32_t p1,
+ v8::internal::Object* Call(int32_t entry, int32_t p0, int32_t p1,
int32_t p2, int32_t p3, int32_t p4);
private: