| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 3986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3997 IteratePointer(v, kDebugInfoOffset); | 3997 IteratePointer(v, kDebugInfoOffset); |
| 3998 } | 3998 } |
| 3999 | 3999 |
| 4000 | 4000 |
| 4001 void ObjectVisitor::BeginCodeIteration(Code* code) { | 4001 void ObjectVisitor::BeginCodeIteration(Code* code) { |
| 4002 ASSERT(code->ic_flag() == Code::IC_TARGET_IS_OBJECT); | 4002 ASSERT(code->ic_flag() == Code::IC_TARGET_IS_OBJECT); |
| 4003 } | 4003 } |
| 4004 | 4004 |
| 4005 | 4005 |
| 4006 void ObjectVisitor::VisitCodeTarget(RelocInfo* rinfo) { | 4006 void ObjectVisitor::VisitCodeTarget(RelocInfo* rinfo) { |
| 4007 ASSERT(is_code_target(rinfo->rmode())); | 4007 ASSERT(RelocInfo::IsCodeTarget(rinfo->rmode())); |
| 4008 VisitPointer(rinfo->target_object_address()); | 4008 VisitPointer(rinfo->target_object_address()); |
| 4009 } | 4009 } |
| 4010 | 4010 |
| 4011 | 4011 |
| 4012 void ObjectVisitor::VisitDebugTarget(RelocInfo* rinfo) { | 4012 void ObjectVisitor::VisitDebugTarget(RelocInfo* rinfo) { |
| 4013 ASSERT(is_js_return(rinfo->rmode()) && rinfo->is_call_instruction()); | 4013 ASSERT(RelocInfo::IsJSReturn(rinfo->rmode()) && rinfo->is_call_instruction()); |
| 4014 VisitPointer(rinfo->call_object_address()); | 4014 VisitPointer(rinfo->call_object_address()); |
| 4015 } | 4015 } |
| 4016 | 4016 |
| 4017 | 4017 |
| 4018 // Convert relocatable targets from address to code object address. This is | 4018 // Convert relocatable targets from address to code object address. This is |
| 4019 // mainly IC call targets but for debugging straight-line code can be replaced | 4019 // mainly IC call targets but for debugging straight-line code can be replaced |
| 4020 // with a call instruction which also has to be relocated. | 4020 // with a call instruction which also has to be relocated. |
| 4021 void Code::ConvertICTargetsFromAddressToObject() { | 4021 void Code::ConvertICTargetsFromAddressToObject() { |
| 4022 ASSERT(ic_flag() == IC_TARGET_IS_ADDRESS); | 4022 ASSERT(ic_flag() == IC_TARGET_IS_ADDRESS); |
| 4023 | 4023 |
| 4024 for (RelocIterator it(this, RelocInfo::kCodeTargetMask); | 4024 for (RelocIterator it(this, RelocInfo::kCodeTargetMask); |
| 4025 !it.done(); it.next()) { | 4025 !it.done(); it.next()) { |
| 4026 Address ic_addr = it.rinfo()->target_address(); | 4026 Address ic_addr = it.rinfo()->target_address(); |
| 4027 ASSERT(ic_addr != NULL); | 4027 ASSERT(ic_addr != NULL); |
| 4028 HeapObject* code = HeapObject::FromAddress(ic_addr - Code::kHeaderSize); | 4028 HeapObject* code = HeapObject::FromAddress(ic_addr - Code::kHeaderSize); |
| 4029 ASSERT(code->IsHeapObject()); | 4029 ASSERT(code->IsHeapObject()); |
| 4030 it.rinfo()->set_target_object(code); | 4030 it.rinfo()->set_target_object(code); |
| 4031 } | 4031 } |
| 4032 | 4032 |
| 4033 if (Debug::has_break_points()) { | 4033 if (Debug::has_break_points()) { |
| 4034 for (RelocIterator it(this, RelocMask(js_return)); !it.done(); it.next()) { | 4034 for (RelocIterator it(this, RelocInfo::ModeMask(RelocInfo::JS_RETURN)); |
| 4035 !it.done(); |
| 4036 it.next()) { |
| 4035 if (it.rinfo()->is_call_instruction()) { | 4037 if (it.rinfo()->is_call_instruction()) { |
| 4036 Address addr = it.rinfo()->call_address(); | 4038 Address addr = it.rinfo()->call_address(); |
| 4037 ASSERT(addr != NULL); | 4039 ASSERT(addr != NULL); |
| 4038 HeapObject* code = HeapObject::FromAddress(addr - Code::kHeaderSize); | 4040 HeapObject* code = HeapObject::FromAddress(addr - Code::kHeaderSize); |
| 4039 ASSERT(code->IsHeapObject()); | 4041 ASSERT(code->IsHeapObject()); |
| 4040 it.rinfo()->set_call_object(code); | 4042 it.rinfo()->set_call_object(code); |
| 4041 } | 4043 } |
| 4042 } | 4044 } |
| 4043 } | 4045 } |
| 4044 set_ic_flag(IC_TARGET_IS_OBJECT); | 4046 set_ic_flag(IC_TARGET_IS_OBJECT); |
| 4045 } | 4047 } |
| 4046 | 4048 |
| 4047 | 4049 |
| 4048 void Code::CodeIterateBody(ObjectVisitor* v) { | 4050 void Code::CodeIterateBody(ObjectVisitor* v) { |
| 4049 v->BeginCodeIteration(this); | 4051 v->BeginCodeIteration(this); |
| 4050 | 4052 |
| 4051 int mode_mask = RelocInfo::kCodeTargetMask | | 4053 int mode_mask = RelocInfo::kCodeTargetMask | |
| 4052 RelocMask(embedded_object) | | 4054 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | |
| 4053 RelocMask(external_reference) | | 4055 RelocInfo::ModeMask(RelocInfo::EXTERNAL_REFERENCE) | |
| 4054 RelocMask(js_return) | | 4056 RelocInfo::ModeMask(RelocInfo::JS_RETURN) | |
| 4055 RelocMask(runtime_entry); | 4057 RelocInfo::ModeMask(RelocInfo::RUNTIME_ENTRY); |
| 4056 | 4058 |
| 4057 for (RelocIterator it(this, mode_mask); !it.done(); it.next()) { | 4059 for (RelocIterator it(this, mode_mask); !it.done(); it.next()) { |
| 4058 RelocMode rmode = it.rinfo()->rmode(); | 4060 RelocInfo::Mode rmode = it.rinfo()->rmode(); |
| 4059 if (rmode == embedded_object) { | 4061 if (rmode == RelocInfo::EMBEDDED_OBJECT) { |
| 4060 v->VisitPointer(it.rinfo()->target_object_address()); | 4062 v->VisitPointer(it.rinfo()->target_object_address()); |
| 4061 } else if (is_code_target(rmode)) { | 4063 } else if (RelocInfo::IsCodeTarget(rmode)) { |
| 4062 v->VisitCodeTarget(it.rinfo()); | 4064 v->VisitCodeTarget(it.rinfo()); |
| 4063 } else if (rmode == external_reference) { | 4065 } else if (rmode == RelocInfo::EXTERNAL_REFERENCE) { |
| 4064 v->VisitExternalReference(it.rinfo()->target_reference_address()); | 4066 v->VisitExternalReference(it.rinfo()->target_reference_address()); |
| 4065 } else if (Debug::has_break_points() && | 4067 } else if (Debug::has_break_points() && |
| 4066 is_js_return(rmode) && it.rinfo()->is_call_instruction()) { | 4068 RelocInfo::IsJSReturn(rmode) && |
| 4069 it.rinfo()->is_call_instruction()) { |
| 4067 v->VisitDebugTarget(it.rinfo()); | 4070 v->VisitDebugTarget(it.rinfo()); |
| 4068 } else if (rmode == runtime_entry) { | 4071 } else if (rmode == RelocInfo::RUNTIME_ENTRY) { |
| 4069 v->VisitRuntimeEntry(it.rinfo()); | 4072 v->VisitRuntimeEntry(it.rinfo()); |
| 4070 } | 4073 } |
| 4071 } | 4074 } |
| 4072 | 4075 |
| 4073 ScopeInfo<>::IterateScopeInfo(this, v); | 4076 ScopeInfo<>::IterateScopeInfo(this, v); |
| 4074 | 4077 |
| 4075 v->EndCodeIteration(this); | 4078 v->EndCodeIteration(this); |
| 4076 } | 4079 } |
| 4077 | 4080 |
| 4078 | 4081 |
| 4079 void Code::ConvertICTargetsFromObjectToAddress() { | 4082 void Code::ConvertICTargetsFromObjectToAddress() { |
| 4080 ASSERT(ic_flag() == IC_TARGET_IS_OBJECT); | 4083 ASSERT(ic_flag() == IC_TARGET_IS_OBJECT); |
| 4081 | 4084 |
| 4082 for (RelocIterator it(this, RelocInfo::kCodeTargetMask); | 4085 for (RelocIterator it(this, RelocInfo::kCodeTargetMask); |
| 4083 !it.done(); it.next()) { | 4086 !it.done(); it.next()) { |
| 4084 // We cannot use the safe cast (Code::cast) here, because we may be in | 4087 // We cannot use the safe cast (Code::cast) here, because we may be in |
| 4085 // the middle of relocating old objects during GC and the map pointer in | 4088 // the middle of relocating old objects during GC and the map pointer in |
| 4086 // the code object may be mangled | 4089 // the code object may be mangled |
| 4087 Code* code = reinterpret_cast<Code*>(it.rinfo()->target_object()); | 4090 Code* code = reinterpret_cast<Code*>(it.rinfo()->target_object()); |
| 4088 ASSERT((code != NULL) && code->IsHeapObject()); | 4091 ASSERT((code != NULL) && code->IsHeapObject()); |
| 4089 it.rinfo()->set_target_address(code->instruction_start()); | 4092 it.rinfo()->set_target_address(code->instruction_start()); |
| 4090 } | 4093 } |
| 4091 | 4094 |
| 4092 if (Debug::has_break_points()) { | 4095 if (Debug::has_break_points()) { |
| 4093 for (RelocIterator it(this, RelocMask(js_return)); !it.done(); it.next()) { | 4096 for (RelocIterator it(this, RelocInfo::ModeMask(RelocInfo::JS_RETURN)); |
| 4097 !it.done(); |
| 4098 it.next()) { |
| 4094 if (it.rinfo()->is_call_instruction()) { | 4099 if (it.rinfo()->is_call_instruction()) { |
| 4095 Code* code = reinterpret_cast<Code*>(it.rinfo()->call_object()); | 4100 Code* code = reinterpret_cast<Code*>(it.rinfo()->call_object()); |
| 4096 ASSERT((code != NULL) && code->IsHeapObject()); | 4101 ASSERT((code != NULL) && code->IsHeapObject()); |
| 4097 it.rinfo()->set_call_address(code->instruction_start()); | 4102 it.rinfo()->set_call_address(code->instruction_start()); |
| 4098 } | 4103 } |
| 4099 } | 4104 } |
| 4100 } | 4105 } |
| 4101 set_ic_flag(IC_TARGET_IS_ADDRESS); | 4106 set_ic_flag(IC_TARGET_IS_ADDRESS); |
| 4102 } | 4107 } |
| 4103 | 4108 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 4123 } | 4128 } |
| 4124 | 4129 |
| 4125 // copy reloc info | 4130 // copy reloc info |
| 4126 memmove(relocation_start(), | 4131 memmove(relocation_start(), |
| 4127 desc.buffer + desc.buffer_size - desc.reloc_size, | 4132 desc.buffer + desc.buffer_size - desc.reloc_size, |
| 4128 desc.reloc_size); | 4133 desc.reloc_size); |
| 4129 | 4134 |
| 4130 // unbox handles and relocate | 4135 // unbox handles and relocate |
| 4131 int delta = instruction_start() - desc.buffer; | 4136 int delta = instruction_start() - desc.buffer; |
| 4132 int mode_mask = RelocInfo::kCodeTargetMask | | 4137 int mode_mask = RelocInfo::kCodeTargetMask | |
| 4133 RelocMask(embedded_object) | | 4138 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | |
| 4134 RelocInfo::kApplyMask; | 4139 RelocInfo::kApplyMask; |
| 4135 for (RelocIterator it(this, mode_mask); !it.done(); it.next()) { | 4140 for (RelocIterator it(this, mode_mask); !it.done(); it.next()) { |
| 4136 RelocMode mode = it.rinfo()->rmode(); | 4141 RelocInfo::Mode mode = it.rinfo()->rmode(); |
| 4137 if (mode == embedded_object) { | 4142 if (mode == RelocInfo::EMBEDDED_OBJECT) { |
| 4138 Object** p = reinterpret_cast<Object**>(it.rinfo()->target_object()); | 4143 Object** p = reinterpret_cast<Object**>(it.rinfo()->target_object()); |
| 4139 it.rinfo()->set_target_object(*p); | 4144 it.rinfo()->set_target_object(*p); |
| 4140 } else if (is_code_target(mode)) { | 4145 } else if (RelocInfo::IsCodeTarget(mode)) { |
| 4141 // rewrite code handles in inline cache targets to direct | 4146 // rewrite code handles in inline cache targets to direct |
| 4142 // pointers to the first instruction in the code object | 4147 // pointers to the first instruction in the code object |
| 4143 Object** p = reinterpret_cast<Object**>(it.rinfo()->target_object()); | 4148 Object** p = reinterpret_cast<Object**>(it.rinfo()->target_object()); |
| 4144 Code* code = Code::cast(*p); | 4149 Code* code = Code::cast(*p); |
| 4145 it.rinfo()->set_target_address(code->instruction_start()); | 4150 it.rinfo()->set_target_address(code->instruction_start()); |
| 4146 } else { | 4151 } else { |
| 4147 it.rinfo()->apply(delta); | 4152 it.rinfo()->apply(delta); |
| 4148 } | 4153 } |
| 4149 } | 4154 } |
| 4150 CPU::FlushICache(instruction_start(), instruction_size()); | 4155 CPU::FlushICache(instruction_start(), instruction_size()); |
| 4151 } | 4156 } |
| 4152 | 4157 |
| 4153 | 4158 |
| 4154 // Locate the source position which is closest to the address in the code. This | 4159 // Locate the source position which is closest to the address in the code. This |
| 4155 // is using the source position information embedded in the relocation info. | 4160 // is using the source position information embedded in the relocation info. |
| 4156 // The position returned is relative to the beginning of the script where the | 4161 // The position returned is relative to the beginning of the script where the |
| 4157 // source for this function is found. | 4162 // source for this function is found. |
| 4158 int Code::SourcePosition(Address pc) { | 4163 int Code::SourcePosition(Address pc) { |
| 4159 int distance = kMaxInt; | 4164 int distance = kMaxInt; |
| 4160 int position = kNoPosition; // Initially no position found. | 4165 int position = RelocInfo::kNoPosition; // Initially no position found. |
| 4161 // Run through all the relocation info to find the best matching source | 4166 // Run through all the relocation info to find the best matching source |
| 4162 // position. All the code needs to be considered as the sequence of the | 4167 // position. All the code needs to be considered as the sequence of the |
| 4163 // instructions in the code does not necessarily follow the same order as the | 4168 // instructions in the code does not necessarily follow the same order as the |
| 4164 // source. | 4169 // source. |
| 4165 RelocIterator it(this, RelocInfo::kPositionMask); | 4170 RelocIterator it(this, RelocInfo::kPositionMask); |
| 4166 while (!it.done()) { | 4171 while (!it.done()) { |
| 4167 // Only look at positions after the current pc. | 4172 // Only look at positions after the current pc. |
| 4168 if (it.rinfo()->pc() < pc) { | 4173 if (it.rinfo()->pc() < pc) { |
| 4169 // Get position and distance. | 4174 // Get position and distance. |
| 4170 int dist = pc - it.rinfo()->pc(); | 4175 int dist = pc - it.rinfo()->pc(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4187 // Same as Code::SourcePosition above except it only looks for statement | 4192 // Same as Code::SourcePosition above except it only looks for statement |
| 4188 // positions. | 4193 // positions. |
| 4189 int Code::SourceStatementPosition(Address pc) { | 4194 int Code::SourceStatementPosition(Address pc) { |
| 4190 // First find the position as close as possible using all position | 4195 // First find the position as close as possible using all position |
| 4191 // information. | 4196 // information. |
| 4192 int position = SourcePosition(pc); | 4197 int position = SourcePosition(pc); |
| 4193 // Now find the closest statement position before the position. | 4198 // Now find the closest statement position before the position. |
| 4194 int statement_position = 0; | 4199 int statement_position = 0; |
| 4195 RelocIterator it(this, RelocInfo::kPositionMask); | 4200 RelocIterator it(this, RelocInfo::kPositionMask); |
| 4196 while (!it.done()) { | 4201 while (!it.done()) { |
| 4197 if (is_statement_position(it.rinfo()->rmode())) { | 4202 if (RelocInfo::IsStatementPosition(it.rinfo()->rmode())) { |
| 4198 int p = it.rinfo()->data(); | 4203 int p = it.rinfo()->data(); |
| 4199 if (statement_position < p && p <= position) { | 4204 if (statement_position < p && p <= position) { |
| 4200 statement_position = p; | 4205 statement_position = p; |
| 4201 } | 4206 } |
| 4202 } | 4207 } |
| 4203 it.next(); | 4208 it.next(); |
| 4204 } | 4209 } |
| 4205 return statement_position; | 4210 return statement_position; |
| 4206 } | 4211 } |
| 4207 | 4212 |
| (...skipping 2097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6305 // No break point. | 6310 // No break point. |
| 6306 if (break_point_objects()->IsUndefined()) return 0; | 6311 if (break_point_objects()->IsUndefined()) return 0; |
| 6307 // Single beak point. | 6312 // Single beak point. |
| 6308 if (!break_point_objects()->IsFixedArray()) return 1; | 6313 if (!break_point_objects()->IsFixedArray()) return 1; |
| 6309 // Multiple break points. | 6314 // Multiple break points. |
| 6310 return FixedArray::cast(break_point_objects())->length(); | 6315 return FixedArray::cast(break_point_objects())->length(); |
| 6311 } | 6316 } |
| 6312 | 6317 |
| 6313 | 6318 |
| 6314 } } // namespace v8::internal | 6319 } } // namespace v8::internal |
| OLD | NEW |