| 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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 } | 288 } |
| 289 | 289 |
| 290 | 290 |
| 291 // ----------------------------------------------------------------------------- | 291 // ----------------------------------------------------------------------------- |
| 292 // Implementation of Assembler. | 292 // Implementation of Assembler. |
| 293 | 293 |
| 294 // Emit a single byte. Must always be inlined. | 294 // Emit a single byte. Must always be inlined. |
| 295 #define EMIT(x) \ | 295 #define EMIT(x) \ |
| 296 *pc_++ = (x) | 296 *pc_++ = (x) |
| 297 | 297 |
| 298 | |
| 299 #ifdef GENERATED_CODE_COVERAGE | |
| 300 static void InitCoverageLog(); | |
| 301 #endif | |
| 302 | |
| 303 Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size) | 298 Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size) |
| 304 : AssemblerBase(isolate, buffer, buffer_size) { | 299 : AssemblerBase(isolate, buffer, buffer_size) { |
| 305 // Clear the buffer in debug mode unless it was provided by the | 300 // Clear the buffer in debug mode unless it was provided by the |
| 306 // caller in which case we can't be sure it's okay to overwrite | 301 // caller in which case we can't be sure it's okay to overwrite |
| 307 // existing code in it; see CodePatcher::CodePatcher(...). | 302 // existing code in it; see CodePatcher::CodePatcher(...). |
| 308 #ifdef DEBUG | 303 #ifdef DEBUG |
| 309 if (own_buffer_) { | 304 if (own_buffer_) { |
| 310 memset(buffer_, 0xCC, buffer_size_); // int3 | 305 memset(buffer_, 0xCC, buffer_size_); // int3 |
| 311 } | 306 } |
| 312 #endif | 307 #endif |
| 313 | 308 |
| 314 reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_); | 309 reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_); |
| 315 | |
| 316 #ifdef GENERATED_CODE_COVERAGE | |
| 317 InitCoverageLog(); | |
| 318 #endif | |
| 319 } | 310 } |
| 320 | 311 |
| 321 | 312 |
| 322 void Assembler::GetCode(CodeDesc* desc) { | 313 void Assembler::GetCode(CodeDesc* desc) { |
| 323 // Finalize code (at this point overflow() may be true, but the gap ensures | 314 // Finalize code (at this point overflow() may be true, but the gap ensures |
| 324 // that we are still not overlapping instructions and relocation info). | 315 // that we are still not overlapping instructions and relocation info). |
| 325 DCHECK(pc_ <= reloc_info_writer.pos()); // No overlap. | 316 DCHECK(pc_ <= reloc_info_writer.pos()); // No overlap. |
| 326 // Set up code descriptor. | 317 // Set up code descriptor. |
| 327 desc->buffer = buffer_; | 318 desc->buffer = buffer_; |
| 328 desc->buffer_size = buffer_size_; | 319 desc->buffer_size = buffer_size_; |
| (...skipping 2734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3063 // Don't record external references unless the heap will be serialized. | 3054 // Don't record external references unless the heap will be serialized. |
| 3064 if (rmode == RelocInfo::EXTERNAL_REFERENCE && | 3055 if (rmode == RelocInfo::EXTERNAL_REFERENCE && |
| 3065 !serializer_enabled() && !emit_debug_code()) { | 3056 !serializer_enabled() && !emit_debug_code()) { |
| 3066 return; | 3057 return; |
| 3067 } | 3058 } |
| 3068 RelocInfo rinfo(isolate(), pc_, rmode, data, NULL); | 3059 RelocInfo rinfo(isolate(), pc_, rmode, data, NULL); |
| 3069 reloc_info_writer.Write(&rinfo); | 3060 reloc_info_writer.Write(&rinfo); |
| 3070 } | 3061 } |
| 3071 | 3062 |
| 3072 | 3063 |
| 3073 #ifdef GENERATED_CODE_COVERAGE | |
| 3074 static FILE* coverage_log = NULL; | |
| 3075 | |
| 3076 | |
| 3077 static void InitCoverageLog() { | |
| 3078 char* file_name = getenv("V8_GENERATED_CODE_COVERAGE_LOG"); | |
| 3079 if (file_name != NULL) { | |
| 3080 coverage_log = fopen(file_name, "aw+"); | |
| 3081 } | |
| 3082 } | |
| 3083 | |
| 3084 | |
| 3085 void LogGeneratedCodeCoverage(const char* file_line) { | |
| 3086 const char* return_address = (&file_line)[-1]; | |
| 3087 char* push_insn = const_cast<char*>(return_address - 12); | |
| 3088 push_insn[0] = 0xeb; // Relative branch insn. | |
| 3089 push_insn[1] = 13; // Skip over coverage insns. | |
| 3090 if (coverage_log != NULL) { | |
| 3091 fprintf(coverage_log, "%s\n", file_line); | |
| 3092 fflush(coverage_log); | |
| 3093 } | |
| 3094 } | |
| 3095 | |
| 3096 #endif | |
| 3097 | |
| 3098 } // namespace internal | 3064 } // namespace internal |
| 3099 } // namespace v8 | 3065 } // namespace v8 |
| 3100 | 3066 |
| 3101 #endif // V8_TARGET_ARCH_IA32 | 3067 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |