| 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // ----------------------------------------------------------------------------- | 228 // ----------------------------------------------------------------------------- |
| 229 // Implementation of Assembler. | 229 // Implementation of Assembler. |
| 230 | 230 |
| 231 // Emit a single byte. Must always be inlined. | 231 // Emit a single byte. Must always be inlined. |
| 232 #define EMIT(x) \ | 232 #define EMIT(x) \ |
| 233 *pc_++ = (x) | 233 *pc_++ = (x) |
| 234 | 234 |
| 235 | 235 |
| 236 #ifdef GENERATED_CODE_COVERAGE | 236 #ifdef GENERATED_CODE_COVERAGE |
| 237 static void InitCoverageLog(); | 237 static void InitCoverageLog(); |
| 238 static void DeinitCoverageLog(); |
| 238 #endif | 239 #endif |
| 239 | 240 |
| 240 Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size) | 241 Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size) |
| 241 : AssemblerBase(isolate, buffer, buffer_size), | 242 : AssemblerBase(isolate, buffer, buffer_size), |
| 242 positions_recorder_(this) { | 243 positions_recorder_(this) { |
| 243 // Clear the buffer in debug mode unless it was provided by the | 244 // Clear the buffer in debug mode unless it was provided by the |
| 244 // caller in which case we can't be sure it's okay to overwrite | 245 // caller in which case we can't be sure it's okay to overwrite |
| 245 // existing code in it; see CodePatcher::CodePatcher(...). | 246 // existing code in it; see CodePatcher::CodePatcher(...). |
| 246 #ifdef DEBUG | 247 #ifdef DEBUG |
| 247 if (own_buffer_) { | 248 if (own_buffer_) { |
| 248 memset(buffer_, 0xCC, buffer_size_); // int3 | 249 memset(buffer_, 0xCC, buffer_size_); // int3 |
| 249 } | 250 } |
| 250 #endif | 251 #endif |
| 251 | 252 |
| 252 reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_); | 253 reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_); |
| 253 | 254 |
| 254 #ifdef GENERATED_CODE_COVERAGE | 255 #ifdef GENERATED_CODE_COVERAGE |
| 255 InitCoverageLog(); | 256 InitCoverageLog(); |
| 256 #endif | 257 #endif |
| 257 } | 258 } |
| 258 | 259 |
| 260 Assembler::~Assembler() { |
| 261 #ifdef GENERATED_CODE_COVERAGE |
| 262 DeinitCoverageLog(); |
| 263 #endif |
| 264 } |
| 259 | 265 |
| 260 void Assembler::GetCode(CodeDesc* desc) { | 266 void Assembler::GetCode(CodeDesc* desc) { |
| 261 // Finalize code (at this point overflow() may be true, but the gap ensures | 267 // Finalize code (at this point overflow() may be true, but the gap ensures |
| 262 // that we are still not overlapping instructions and relocation info). | 268 // that we are still not overlapping instructions and relocation info). |
| 263 ASSERT(pc_ <= reloc_info_writer.pos()); // No overlap. | 269 ASSERT(pc_ <= reloc_info_writer.pos()); // No overlap. |
| 264 // Set up code descriptor. | 270 // Set up code descriptor. |
| 265 desc->buffer = buffer_; | 271 desc->buffer = buffer_; |
| 266 desc->buffer_size = buffer_size_; | 272 desc->buffer_size = buffer_size_; |
| 267 desc->instr_size = pc_offset(); | 273 desc->instr_size = pc_offset(); |
| 268 desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos(); | 274 desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos(); |
| (...skipping 2346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2615 return; | 2621 return; |
| 2616 } | 2622 } |
| 2617 | 2623 |
| 2618 | 2624 |
| 2619 #ifdef GENERATED_CODE_COVERAGE | 2625 #ifdef GENERATED_CODE_COVERAGE |
| 2620 static FILE* coverage_log = NULL; | 2626 static FILE* coverage_log = NULL; |
| 2621 | 2627 |
| 2622 | 2628 |
| 2623 static void InitCoverageLog() { | 2629 static void InitCoverageLog() { |
| 2624 char* file_name = getenv("V8_GENERATED_CODE_COVERAGE_LOG"); | 2630 char* file_name = getenv("V8_GENERATED_CODE_COVERAGE_LOG"); |
| 2625 if (file_name != NULL) { | 2631 if (file_name != NULL && NULL == coverage_log) { |
| 2626 coverage_log = fopen(file_name, "aw+"); | 2632 coverage_log = fopen(file_name, "aw+"); |
| 2627 } | 2633 } |
| 2628 } | 2634 } |
| 2629 | 2635 |
| 2636 static void DeinitCoverageLog() { |
| 2637 if (coverage_log != NULL) { |
| 2638 fclose(coverage_log); |
| 2639 coverage_log = NULL; |
| 2640 } |
| 2641 } |
| 2630 | 2642 |
| 2631 void LogGeneratedCodeCoverage(const char* file_line) { | 2643 void LogGeneratedCodeCoverage(const char* file_line) { |
| 2632 const char* return_address = (&file_line)[-1]; | 2644 const char* return_address = (&file_line)[-1]; |
| 2633 char* push_insn = const_cast<char*>(return_address - 12); | 2645 char* push_insn = const_cast<char*>(return_address - 12); |
| 2634 push_insn[0] = 0xeb; // Relative branch insn. | 2646 push_insn[0] = 0xeb; // Relative branch insn. |
| 2635 push_insn[1] = 13; // Skip over coverage insns. | 2647 push_insn[1] = 13; // Skip over coverage insns. |
| 2636 if (coverage_log != NULL) { | 2648 if (coverage_log != NULL) { |
| 2637 fprintf(coverage_log, "%s\n", file_line); | 2649 fprintf(coverage_log, "%s\n", file_line); |
| 2638 fflush(coverage_log); | 2650 fflush(coverage_log); |
| 2639 } | 2651 } |
| 2640 } | 2652 } |
| 2641 | 2653 |
| 2642 #endif | 2654 #endif |
| 2643 | 2655 |
| 2644 } } // namespace v8::internal | 2656 } } // namespace v8::internal |
| 2645 | 2657 |
| 2646 #endif // V8_TARGET_ARCH_IA32 | 2658 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |