Commit bbbab482 authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

Refactor the convertion of a target address into a code object from the debugger to the Code class.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@952 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 19bb4fd6
...@@ -450,7 +450,7 @@ void RelocInfo::Print() { ...@@ -450,7 +450,7 @@ void RelocInfo::Print() {
ref_encoder.NameOfAddress(*target_reference_address()), ref_encoder.NameOfAddress(*target_reference_address()),
*target_reference_address()); *target_reference_address());
} else if (IsCodeTarget(rmode_)) { } 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()); PrintF(" (%s) (%p)", Code::Kind2String(code->kind()), target_address());
} else if (IsPosition(rmode_)) { } else if (IsPosition(rmode_)) {
PrintF(" (%d)", data()); PrintF(" (%d)", data());
......
...@@ -113,7 +113,7 @@ void BreakLocationIterator::Next() { ...@@ -113,7 +113,7 @@ void BreakLocationIterator::Next() {
// be of a different kind than in the original code. // be of a different kind than in the original code.
if (RelocInfo::IsCodeTarget(rmode())) { if (RelocInfo::IsCodeTarget(rmode())) {
Address target = original_rinfo()->target_address(); 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())) { if (code->is_inline_cache_stub() || RelocInfo::IsConstructCall(rmode())) {
break_point_++; break_point_++;
return; return;
...@@ -325,7 +325,7 @@ void BreakLocationIterator::PrepareStepIn() { ...@@ -325,7 +325,7 @@ void BreakLocationIterator::PrepareStepIn() {
// Step in can only be prepared if currently positioned on an IC call or // Step in can only be prepared if currently positioned on an IC call or
// construct call. // construct call.
Address target = rinfo()->target_address(); Address target = rinfo()->target_address();
Code* code = Debug::GetCodeTarget(target); Code* code = Code::GetCodeFromTargetAddress(target);
if (code->is_call_stub()) { if (code->is_call_stub()) {
// Step in through IC call is handled by the runtime system. Therefore make // 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 // 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) { ...@@ -923,7 +923,7 @@ void Debug::PrepareStep(StepAction step_action, int step_count) {
bool is_call_target = false; bool is_call_target = false;
if (RelocInfo::IsCodeTarget(it.rinfo()->rmode())) { if (RelocInfo::IsCodeTarget(it.rinfo()->rmode())) {
Address target = it.rinfo()->target_address(); 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; if (code->is_call_stub()) is_call_target = true;
} }
...@@ -991,7 +991,7 @@ bool Debug::StepNextContinue(BreakLocationIterator* break_location_iterator, ...@@ -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 // Check whether the code object at the specified address is a debug break code
// object. // object.
bool Debug::IsDebugBreak(Address addr) { bool Debug::IsDebugBreak(Address addr) {
Code* code = GetCodeTarget(addr); Code* code = Code::GetCodeFromTargetAddress(addr);
return code->ic_state() == DEBUG_BREAK; return code->ic_state() == DEBUG_BREAK;
} }
...@@ -1021,7 +1021,7 @@ Handle<Code> Debug::FindDebugBreak(RelocInfo* rinfo) { ...@@ -1021,7 +1021,7 @@ Handle<Code> Debug::FindDebugBreak(RelocInfo* rinfo) {
if (RelocInfo::IsCodeTarget(mode)) { if (RelocInfo::IsCodeTarget(mode)) {
Address target = rinfo->target_address(); Address target = rinfo->target_address();
Code* code = Debug::GetCodeTarget(target); Code* code = Code::GetCodeFromTargetAddress(target);
if (code->is_inline_cache_stub()) { if (code->is_inline_cache_stub()) {
if (code->is_call_stub()) { if (code->is_call_stub()) {
return ComputeCallDebugBreak(code->arguments_count()); return ComputeCallDebugBreak(code->arguments_count());
...@@ -1262,14 +1262,6 @@ void Debug::SetAfterBreakTarget(JavaScriptFrame* frame) { ...@@ -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) { bool Debug::IsDebugGlobal(GlobalObject* global) {
return IsLoaded() && global == Debug::debug_context()->global(); return IsLoaded() && global == Debug::debug_context()->global();
} }
......
...@@ -194,7 +194,6 @@ class Debug { ...@@ -194,7 +194,6 @@ class Debug {
static Handle<Object> GetSourceBreakLocations( static Handle<Object> GetSourceBreakLocations(
Handle<SharedFunctionInfo> shared); Handle<SharedFunctionInfo> shared);
static Code* GetCodeTarget(Address target);
// Getter for the debug_context. // Getter for the debug_context.
inline static Handle<Context> debug_context() { return debug_context_; } inline static Handle<Context> debug_context() { return debug_context_; }
......
...@@ -228,7 +228,7 @@ static int DecodeIt(FILE* f, ...@@ -228,7 +228,7 @@ static int DecodeIt(FILE* f,
if (rmode == RelocInfo::CONSTRUCT_CALL) { if (rmode == RelocInfo::CONSTRUCT_CALL) {
out.AddFormatted(" constructor,"); out.AddFormatted(" constructor,");
} }
Code* code = Debug::GetCodeTarget(relocinfo.target_address()); Code* code = Code::GetCodeFromTargetAddress(relocinfo.target_address());
Code::Kind kind = code->kind(); Code::Kind kind = code->kind();
if (code->is_inline_cache_stub()) { if (code->is_inline_cache_stub()) {
if (rmode == RelocInfo::CODE_TARGET_CONTEXT) { if (rmode == RelocInfo::CODE_TARGET_CONTEXT) {
......
...@@ -59,14 +59,11 @@ Address IC::address() { ...@@ -59,14 +59,11 @@ Address IC::address() {
Code* IC::GetTargetAtAddress(Address address) { Code* IC::GetTargetAtAddress(Address address) {
// Get the target address of the IC.
Address target = Assembler::target_address_at(address); Address target = Assembler::target_address_at(address);
HeapObject* code = HeapObject::FromAddress(target - Code::kHeaderSize); // Convert target address to the code object. Code::GetCodeFromTargetAddress
// GetTargetAtAddress is called from IC::Clear which in turn is // is safe for use during GC where the map might be marked.
// called when marking objects during mark sweep. reinterpret_cast Code* result = Code::GetCodeFromTargetAddress(target);
// 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);
ASSERT(result->is_inline_cache_stub()); ASSERT(result->is_inline_cache_stub());
return result; return result;
} }
......
...@@ -1877,6 +1877,17 @@ Code::Flags Code::RemoveTypeFromFlags(Flags flags) { ...@@ -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() { Object* Map::prototype() {
return READ_FIELD(this, kPrototypeOffset); return READ_FIELD(this, kPrototypeOffset);
} }
......
...@@ -2201,6 +2201,8 @@ class Code: public HeapObject { ...@@ -2201,6 +2201,8 @@ class Code: public HeapObject {
static inline int ExtractArgumentsCountFromFlags(Flags flags); static inline int ExtractArgumentsCountFromFlags(Flags flags);
static inline Flags RemoveTypeFromFlags(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. // Returns the address of the first instruction.
inline byte* instruction_start(); inline byte* instruction_start();
......
...@@ -397,7 +397,7 @@ void CheckDebugBreakFunction(DebugLocalContext* env, ...@@ -397,7 +397,7 @@ void CheckDebugBreakFunction(DebugLocalContext* env,
CHECK_EQ(mode, it1.it()->rinfo()->rmode()); CHECK_EQ(mode, it1.it()->rinfo()->rmode());
if (mode != v8::internal::RelocInfo::JS_RETURN) { if (mode != v8::internal::RelocInfo::JS_RETURN) {
CHECK_EQ(debug_break, CHECK_EQ(debug_break,
Debug::GetCodeTarget(it1.it()->rinfo()->target_address())); Code::GetCodeFromTargetAddress(it1.it()->rinfo()->target_address()));
} else { } else {
// TODO(1240753): Make the test architecture independent or split // TODO(1240753): Make the test architecture independent or split
// parts of the debugger into architecture dependent files. // parts of the debugger into architecture dependent files.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment