Some fixes in ARM simulator:
authorfeng@chromium.org <feng@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 12 Nov 2008 22:57:04 +0000 (22:57 +0000)
committerfeng@chromium.org <feng@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Wed, 12 Nov 2008 22:57:04 +0000 (22:57 +0000)
1) create a simulator per thread and using thread storage;
2) capitalize two function names;
3) use sscanf instead of sscanf_s in arm simulator;
4) disable warning of sscanf when building with arm simulator;

Review URL: http://codereview.chromium.org/10634

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@743 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

SConstruct
src/simulator-arm.cc
src/simulator-arm.h
tools/visual_studio/arm.vsprops

index c1a6ec2..9dd9268 100644 (file)
@@ -106,7 +106,10 @@ V8_EXTRA_FLAGS = {
       'CPPDEFINES':   ['BUILDING_V8_SHARED']
     },
     'arch:arm': {
-      'CPPDEFINES':   ['ARM']
+      'CPPDEFINES':   ['ARM'],
+      # /wd4996 is to silence the warning about sscanf
+      # used by the arm simulator.
+      'WARNINGFLAGS': ['/wd4996']
     },
     'disassembler:on': {
       'CPPDEFINES':   ['ENABLE_DISASSEMBLER']
index 25f27e1..4203ad3 100644 (file)
@@ -48,11 +48,7 @@ using ::v8::internal::DeleteArray;
 // 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.
@@ -382,19 +378,20 @@ Simulator::Simulator() {
 }
 
 
-// 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;
 }
 
 
@@ -1495,7 +1492,7 @@ void Simulator::InstructionDecode(Instr* instr) {
 
 
 //
-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();
@@ -1527,7 +1524,7 @@ void Simulator::execute() {
 }
 
 
-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);
@@ -1570,7 +1567,7 @@ Object* Simulator::call(int32_t entry, int32_t p0, int32_t p1, int32_t p2,
   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);
index baefa5d..ccb3e80 100644 (file)
@@ -54,7 +54,7 @@
 // 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
@@ -103,12 +103,12 @@ class Simulator {
   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:
index 364e1bc..0e37d41 100644 (file)
@@ -7,5 +7,6 @@
        <Tool
                Name="VCCLCompilerTool"
                PreprocessorDefinitions="ARM"
+               DisableSpecificWarnings="4996"
        />
 </VisualStudioPropertySheet>