Refactor the convertion of a target address into a code object from the debugger...
authorsgjesse@chromium.org <sgjesse@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 9 Dec 2008 12:53:59 +0000 (12:53 +0000)
committersgjesse@chromium.org <sgjesse@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 9 Dec 2008 12:53:59 +0000 (12:53 +0000)
Review URL: http://codereview.chromium.org/13285

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

src/assembler.cc
src/debug.cc
src/debug.h
src/disassembler.cc
src/ic-inl.h
src/objects-inl.h
src/objects.h
test/cctest/test-debug.cc

index 1fd0dc343c0d440672ed8bbe37f1daed97c6e9f6..c56eb2f73194c0acabcde00456142c37cd0ec522 100644 (file)
@@ -450,7 +450,7 @@ void RelocInfo::Print() {
            ref_encoder.NameOfAddress(*target_reference_address()),
            *target_reference_address());
   } else if (IsCodeTarget(rmode_)) {
-    Code* code = Debug::GetCodeTarget(target_address());
+    Code* code = Code::GetCodeFromTargetAddress(target_address());
     PrintF(" (%s)  (%p)", Code::Kind2String(code->kind()), target_address());
   } else if (IsPosition(rmode_)) {
     PrintF("  (%d)", data());
index 6952d8b190d711947394aca96ae4b57b04ede7db..f31b475bfb9814937f1e99a56e3e78e70fcc03fb 100644 (file)
@@ -113,7 +113,7 @@ void BreakLocationIterator::Next() {
     // be of a different kind than in the original code.
     if (RelocInfo::IsCodeTarget(rmode())) {
       Address target = original_rinfo()->target_address();
-      Code* code = Debug::GetCodeTarget(target);
+      Code* code = Code::GetCodeFromTargetAddress(target);
       if (code->is_inline_cache_stub() || RelocInfo::IsConstructCall(rmode())) {
         break_point_++;
         return;
@@ -325,7 +325,7 @@ void BreakLocationIterator::PrepareStepIn() {
   // Step in can only be prepared if currently positioned on an IC call or
   // construct call.
   Address target = rinfo()->target_address();
-  Code* code = Debug::GetCodeTarget(target);
+  Code* code = Code::GetCodeFromTargetAddress(target);
   if (code->is_call_stub()) {
     // Step in through IC call is handled by the runtime system. Therefore make
     // sure that the any current IC is cleared and the runtime system is
@@ -923,7 +923,7 @@ void Debug::PrepareStep(StepAction step_action, int step_count) {
   bool is_call_target = false;
   if (RelocInfo::IsCodeTarget(it.rinfo()->rmode())) {
     Address target = it.rinfo()->target_address();
-    Code* code = Debug::GetCodeTarget(target);
+    Code* code = Code::GetCodeFromTargetAddress(target);
     if (code->is_call_stub()) is_call_target = true;
   }
 
@@ -991,7 +991,7 @@ bool Debug::StepNextContinue(BreakLocationIterator* break_location_iterator,
 // Check whether the code object at the specified address is a debug break code
 // object.
 bool Debug::IsDebugBreak(Address addr) {
-  Code* code = GetCodeTarget(addr);
+  Code* code = Code::GetCodeFromTargetAddress(addr);
   return code->ic_state() == DEBUG_BREAK;
 }
 
@@ -1021,7 +1021,7 @@ Handle<Code> Debug::FindDebugBreak(RelocInfo* rinfo) {
 
   if (RelocInfo::IsCodeTarget(mode)) {
     Address target = rinfo->target_address();
-    Code* code = Debug::GetCodeTarget(target);
+    Code* code = Code::GetCodeFromTargetAddress(target);
     if (code->is_inline_cache_stub()) {
       if (code->is_call_stub()) {
         return ComputeCallDebugBreak(code->arguments_count());
@@ -1262,14 +1262,6 @@ void Debug::SetAfterBreakTarget(JavaScriptFrame* frame) {
 }
 
 
-Code* Debug::GetCodeTarget(Address target) {
-  // Maybe this can be refactored with the stuff in ic-inl.h?
-  Code* result =
-      Code::cast(HeapObject::FromAddress(target - Code::kHeaderSize));
-  return result;
-}
-
-
 bool Debug::IsDebugGlobal(GlobalObject* global) {
   return IsLoaded() && global == Debug::debug_context()->global();
 }
index d1615a36f67c5072a31c762bd37a8c34782fc852..a5f9b201ccc52ba7ee58fce9f809092e428eaf82 100644 (file)
@@ -194,7 +194,6 @@ class Debug {
 
   static Handle<Object> GetSourceBreakLocations(
       Handle<SharedFunctionInfo> shared);
-  static Code* GetCodeTarget(Address target);
 
   // Getter for the debug_context.
   inline static Handle<Context> debug_context() { return debug_context_; }
index 53f594f3b4d227730c3ec201dff9c8011ef11b1f..af7df2679173f7a22564452c26434d3dd20daa0d 100644 (file)
@@ -228,7 +228,7 @@ static int DecodeIt(FILE* f,
         if (rmode == RelocInfo::CONSTRUCT_CALL) {
           out.AddFormatted(" constructor,");
         }
-        Code* code = Debug::GetCodeTarget(relocinfo.target_address());
+        Code* code = Code::GetCodeFromTargetAddress(relocinfo.target_address());
         Code::Kind kind = code->kind();
         if (code->is_inline_cache_stub()) {
           if (rmode == RelocInfo::CODE_TARGET_CONTEXT) {
index 201048ad7c9dfcf01c938f08e56676f017947177..f5ce0adf1e1239f55b0b46701112ea0c82cc381a 100644 (file)
@@ -59,14 +59,11 @@ Address IC::address() {
 
 
 Code* IC::GetTargetAtAddress(Address address) {
+  // Get the target address of the IC.
   Address target = Assembler::target_address_at(address);
-  HeapObject* code = HeapObject::FromAddress(target - Code::kHeaderSize);
-  // GetTargetAtAddress is called from IC::Clear which in turn is
-  // called when marking objects during mark sweep. reinterpret_cast
-  // is therefore used instead of the more appropriate
-  // Code::cast. Code::cast does not work when the object's map is
-  // marked.
-  Code* result = reinterpret_cast<Code*>(code);
+  // Convert target address to the code object. Code::GetCodeFromTargetAddress
+  // is safe for use during GC where the map might be marked.
+  Code* result = Code::GetCodeFromTargetAddress(target);
   ASSERT(result->is_inline_cache_stub());
   return result;
 }
index e8c4e9149cb0eb9ca2563ec5575f212834f6100e..5c70463ac5f8fb98873b4879c2757b101d075ff6 100644 (file)
@@ -1877,6 +1877,17 @@ Code::Flags Code::RemoveTypeFromFlags(Flags flags) {
 }
 
 
+Code* Code::GetCodeFromTargetAddress(Address address) {
+  HeapObject* code = HeapObject::FromAddress(address - Code::kHeaderSize);
+  // GetCodeFromTargetAddress might be called when marking objects during mark
+  // sweep. reinterpret_cast is therefore used instead of the more appropriate
+  // Code::cast. Code::cast does not work when the object's map is
+  // marked.
+  Code* result = reinterpret_cast<Code*>(code);
+  return result;
+}
+
+
 Object* Map::prototype() {
   return READ_FIELD(this, kPrototypeOffset);
 }
index b7e77c20e2da1ccd7e7f5518998f4637b4174823..f400e99710dee08aea7656b50cd2cbc7b68e78c6 100644 (file)
@@ -2201,6 +2201,8 @@ class Code: public HeapObject {
   static inline int ExtractArgumentsCountFromFlags(Flags flags);
   static inline Flags RemoveTypeFromFlags(Flags flags);
 
+  // Convert a target address into a code object.
+  static inline Code* GetCodeFromTargetAddress(Address address);
 
   // Returns the address of the first instruction.
   inline byte* instruction_start();
index 81ce21fa7748ae0bdd4bebeac61a84a6a0bc6a2f..570256e27a262f37c9b6af395bc702da613e7ec2 100644 (file)
@@ -397,7 +397,7 @@ void CheckDebugBreakFunction(DebugLocalContext* env,
   CHECK_EQ(mode, it1.it()->rinfo()->rmode());
   if (mode != v8::internal::RelocInfo::JS_RETURN) {
     CHECK_EQ(debug_break,
-             Debug::GetCodeTarget(it1.it()->rinfo()->target_address()));
+        Code::GetCodeFromTargetAddress(it1.it()->rinfo()->target_address()));
   } else {
     // TODO(1240753): Make the test architecture independent or split
     // parts of the debugger into architecture dependent files.