| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #if V8_TARGET_ARCH_X64 | 7 #if V8_TARGET_ARCH_X64 |
| 8 | 8 |
| 9 #include "src/macro-assembler.h" | 9 #include "src/macro-assembler.h" |
| 10 #include "src/serialize.h" | 10 #include "src/serialize.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 return code == base_code; | 218 return code == base_code; |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 | 222 |
| 223 // ----------------------------------------------------------------------------- | 223 // ----------------------------------------------------------------------------- |
| 224 // Implementation of Assembler. | 224 // Implementation of Assembler. |
| 225 | 225 |
| 226 #ifdef GENERATED_CODE_COVERAGE | 226 #ifdef GENERATED_CODE_COVERAGE |
| 227 static void InitCoverageLog(); | 227 static void InitCoverageLog(); |
| 228 static void DeinitCoverageLog(); |
| 228 #endif | 229 #endif |
| 229 | 230 |
| 230 Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size) | 231 Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size) |
| 231 : AssemblerBase(isolate, buffer, buffer_size), | 232 : AssemblerBase(isolate, buffer, buffer_size), |
| 232 code_targets_(100), | 233 code_targets_(100), |
| 233 positions_recorder_(this) { | 234 positions_recorder_(this) { |
| 234 // Clear the buffer in debug mode unless it was provided by the | 235 // Clear the buffer in debug mode unless it was provided by the |
| 235 // caller in which case we can't be sure it's okay to overwrite | 236 // caller in which case we can't be sure it's okay to overwrite |
| 236 // existing code in it. | 237 // existing code in it. |
| 237 #ifdef DEBUG | 238 #ifdef DEBUG |
| 238 if (own_buffer_) { | 239 if (own_buffer_) { |
| 239 memset(buffer_, 0xCC, buffer_size_); // int3 | 240 memset(buffer_, 0xCC, buffer_size_); // int3 |
| 240 } | 241 } |
| 241 #endif | 242 #endif |
| 242 | 243 |
| 243 reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_); | 244 reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_); |
| 244 | 245 |
| 245 | 246 |
| 246 #ifdef GENERATED_CODE_COVERAGE | 247 #ifdef GENERATED_CODE_COVERAGE |
| 247 InitCoverageLog(); | 248 InitCoverageLog(); |
| 248 #endif | 249 #endif |
| 249 } | 250 } |
| 250 | 251 |
| 252 Assembler::~Assembler() { |
| 253 #ifdef GENERATED_CODE_COVERAGE |
| 254 DeinitCoverageLog(); |
| 255 #endif |
| 256 } |
| 251 | 257 |
| 252 void Assembler::GetCode(CodeDesc* desc) { | 258 void Assembler::GetCode(CodeDesc* desc) { |
| 253 // Finalize code (at this point overflow() may be true, but the gap ensures | 259 // Finalize code (at this point overflow() may be true, but the gap ensures |
| 254 // that we are still not overlapping instructions and relocation info). | 260 // that we are still not overlapping instructions and relocation info). |
| 255 ASSERT(pc_ <= reloc_info_writer.pos()); // No overlap. | 261 ASSERT(pc_ <= reloc_info_writer.pos()); // No overlap. |
| 256 // Set up code descriptor. | 262 // Set up code descriptor. |
| 257 desc->buffer = buffer_; | 263 desc->buffer = buffer_; |
| 258 desc->buffer_size = buffer_size_; | 264 desc->buffer_size = buffer_size_; |
| 259 desc->instr_size = pc_offset(); | 265 desc->instr_size = pc_offset(); |
| 260 ASSERT(desc->instr_size > 0); // Zero-size code objects upset the system. | 266 ASSERT(desc->instr_size > 0); // Zero-size code objects upset the system. |
| (...skipping 2703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2964 // specially coded on x64 means that it is a relative 32 bit address, as used | 2970 // specially coded on x64 means that it is a relative 32 bit address, as used |
| 2965 // by branch instructions. | 2971 // by branch instructions. |
| 2966 return (1 << rmode_) & kApplyMask; | 2972 return (1 << rmode_) & kApplyMask; |
| 2967 } | 2973 } |
| 2968 | 2974 |
| 2969 | 2975 |
| 2970 bool RelocInfo::IsInConstantPool() { | 2976 bool RelocInfo::IsInConstantPool() { |
| 2971 return false; | 2977 return false; |
| 2972 } | 2978 } |
| 2973 | 2979 |
| 2980 #ifdef GENERATED_CODE_COVERAGE |
| 2981 static FILE* coverage_log = NULL; |
| 2982 |
| 2983 |
| 2984 static void InitCoverageLog() { |
| 2985 char* file_name = getenv("V8_GENERATED_CODE_COVERAGE_LOG"); |
| 2986 if (file_name != NULL && NULL == coverage_log) { |
| 2987 coverage_log = fopen(file_name, "aw+"); |
| 2988 } |
| 2989 } |
| 2990 |
| 2991 static void DeinitCoverageLog() { |
| 2992 if (coverage_log != NULL) { |
| 2993 fclose(coverage_log); |
| 2994 coverage_log = NULL; |
| 2995 } |
| 2996 } |
| 2997 |
| 2998 void LogGeneratedCodeCoverage(const char* file_line) { |
| 2999 const char* return_address = (&file_line)[-1]; |
| 3000 char* push_insn = const_cast<char*>(return_address - 12); |
| 3001 push_insn[0] = 0xeb; // Relative branch insn. |
| 3002 push_insn[1] = 13; // Skip over coverage insns. |
| 3003 if (coverage_log != NULL) { |
| 3004 fprintf(coverage_log, "%s\n", file_line); |
| 3005 fflush(coverage_log); |
| 3006 } |
| 3007 } |
| 3008 |
| 3009 #endif |
| 2974 | 3010 |
| 2975 } } // namespace v8::internal | 3011 } } // namespace v8::internal |
| 2976 | 3012 |
| 2977 #endif // V8_TARGET_ARCH_X64 | 3013 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |