OLD | NEW |
1 // Copyright (c) 1994-2006 Sun Microsystems Inc. | 1 // Copyright (c) 1994-2006 Sun Microsystems Inc. |
2 // All Rights Reserved. | 2 // All Rights Reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions | 5 // modification, are permitted provided that the following conditions |
6 // are met: | 6 // are met: |
7 // | 7 // |
8 // - Redistributions of source code must retain the above copyright notice, | 8 // - Redistributions of source code must retain the above copyright notice, |
9 // this list of conditions and the following disclaimer. | 9 // this list of conditions and the following disclaimer. |
10 // | 10 // |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 } | 203 } |
204 | 204 |
205 | 205 |
206 // ----------------------------------------------------------------------------- | 206 // ----------------------------------------------------------------------------- |
207 // Implementation of Assembler. | 207 // Implementation of Assembler. |
208 | 208 |
209 // Emit a single byte. Must always be inlined. | 209 // Emit a single byte. Must always be inlined. |
210 #define EMIT(x) \ | 210 #define EMIT(x) \ |
211 *pc_++ = (x) | 211 *pc_++ = (x) |
212 | 212 |
213 | |
214 #ifdef GENERATED_CODE_COVERAGE | |
215 static void InitCoverageLog(); | |
216 #endif | |
217 | |
218 Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size) | 213 Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size) |
219 : AssemblerBase(isolate, buffer, buffer_size) { | 214 : AssemblerBase(isolate, buffer, buffer_size) { |
220 // Clear the buffer in debug mode unless it was provided by the | 215 // Clear the buffer in debug mode unless it was provided by the |
221 // caller in which case we can't be sure it's okay to overwrite | 216 // caller in which case we can't be sure it's okay to overwrite |
222 // existing code in it; see CodePatcher::CodePatcher(...). | 217 // existing code in it; see CodePatcher::CodePatcher(...). |
223 #ifdef DEBUG | 218 #ifdef DEBUG |
224 if (own_buffer_) { | 219 if (own_buffer_) { |
225 memset(buffer_, 0xCC, buffer_size_); // int3 | 220 memset(buffer_, 0xCC, buffer_size_); // int3 |
226 } | 221 } |
227 #endif | 222 #endif |
228 | 223 |
229 reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_); | 224 reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_); |
230 | |
231 #ifdef GENERATED_CODE_COVERAGE | |
232 InitCoverageLog(); | |
233 #endif | |
234 } | 225 } |
235 | 226 |
236 | 227 |
237 void Assembler::GetCode(CodeDesc* desc) { | 228 void Assembler::GetCode(CodeDesc* desc) { |
238 // Finalize code (at this point overflow() may be true, but the gap ensures | 229 // Finalize code (at this point overflow() may be true, but the gap ensures |
239 // that we are still not overlapping instructions and relocation info). | 230 // that we are still not overlapping instructions and relocation info). |
240 DCHECK(pc_ <= reloc_info_writer.pos()); // No overlap. | 231 DCHECK(pc_ <= reloc_info_writer.pos()); // No overlap. |
241 // Set up code descriptor. | 232 // Set up code descriptor. |
242 desc->buffer = buffer_; | 233 desc->buffer = buffer_; |
243 desc->buffer_size = buffer_size_; | 234 desc->buffer_size = buffer_size_; |
(...skipping 1957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2201 DCHECK(!RelocInfo::IsNone(rmode)); | 2192 DCHECK(!RelocInfo::IsNone(rmode)); |
2202 // Don't record external references unless the heap will be serialized. | 2193 // Don't record external references unless the heap will be serialized. |
2203 if (rmode == RelocInfo::EXTERNAL_REFERENCE && | 2194 if (rmode == RelocInfo::EXTERNAL_REFERENCE && |
2204 !serializer_enabled() && !emit_debug_code()) { | 2195 !serializer_enabled() && !emit_debug_code()) { |
2205 return; | 2196 return; |
2206 } | 2197 } |
2207 RelocInfo rinfo(isolate(), pc_, rmode, data, NULL); | 2198 RelocInfo rinfo(isolate(), pc_, rmode, data, NULL); |
2208 reloc_info_writer.Write(&rinfo); | 2199 reloc_info_writer.Write(&rinfo); |
2209 } | 2200 } |
2210 | 2201 |
2211 | |
2212 #ifdef GENERATED_CODE_COVERAGE | |
2213 static FILE* coverage_log = NULL; | |
2214 | |
2215 | |
2216 static void InitCoverageLog() { | |
2217 char* file_name = getenv("V8_GENERATED_CODE_COVERAGE_LOG"); | |
2218 if (file_name != NULL) { | |
2219 coverage_log = fopen(file_name, "aw+"); | |
2220 } | |
2221 } | |
2222 | |
2223 | |
2224 void LogGeneratedCodeCoverage(const char* file_line) { | |
2225 const char* return_address = (&file_line)[-1]; | |
2226 char* push_insn = const_cast<char*>(return_address - 12); | |
2227 push_insn[0] = 0xeb; // Relative branch insn. | |
2228 push_insn[1] = 13; // Skip over coverage insns. | |
2229 if (coverage_log != NULL) { | |
2230 fprintf(coverage_log, "%s\n", file_line); | |
2231 fflush(coverage_log); | |
2232 } | |
2233 } | |
2234 | |
2235 #endif | |
2236 | |
2237 } // namespace internal | 2202 } // namespace internal |
2238 } // namespace v8 | 2203 } // namespace v8 |
2239 | 2204 |
2240 #endif // V8_TARGET_ARCH_X87 | 2205 #endif // V8_TARGET_ARCH_X87 |
OLD | NEW |