Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Side by Side Diff: src/x87/assembler-x87.cc

Issue 419343003: when open macro GENERATED_CODE_COVERAGE, fix compiler error and fd leak (Closed) Base URL: https://github.com/v8/v8.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/x87/assembler-x87.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 // ----------------------------------------------------------------------------- 223 // -----------------------------------------------------------------------------
224 // Implementation of Assembler. 224 // Implementation of Assembler.
225 225
226 // Emit a single byte. Must always be inlined. 226 // Emit a single byte. Must always be inlined.
227 #define EMIT(x) \ 227 #define EMIT(x) \
228 *pc_++ = (x) 228 *pc_++ = (x)
229 229
230 230
231 #ifdef GENERATED_CODE_COVERAGE 231 #ifdef GENERATED_CODE_COVERAGE
232 static void InitCoverageLog(); 232 static void InitCoverageLog();
233 static void DeinitCoverageLog();
233 #endif 234 #endif
234 235
235 Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size) 236 Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size)
236 : AssemblerBase(isolate, buffer, buffer_size), 237 : AssemblerBase(isolate, buffer, buffer_size),
237 positions_recorder_(this) { 238 positions_recorder_(this) {
238 // Clear the buffer in debug mode unless it was provided by the 239 // Clear the buffer in debug mode unless it was provided by the
239 // caller in which case we can't be sure it's okay to overwrite 240 // caller in which case we can't be sure it's okay to overwrite
240 // existing code in it; see CodePatcher::CodePatcher(...). 241 // existing code in it; see CodePatcher::CodePatcher(...).
241 #ifdef DEBUG 242 #ifdef DEBUG
242 if (own_buffer_) { 243 if (own_buffer_) {
243 memset(buffer_, 0xCC, buffer_size_); // int3 244 memset(buffer_, 0xCC, buffer_size_); // int3
244 } 245 }
245 #endif 246 #endif
246 247
247 reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_); 248 reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_);
248 249
249 #ifdef GENERATED_CODE_COVERAGE 250 #ifdef GENERATED_CODE_COVERAGE
250 InitCoverageLog(); 251 InitCoverageLog();
251 #endif 252 #endif
252 } 253 }
253 254
255 Assembler::~Assembler() {
256 #ifdef GENERATED_CODE_COVERAGE
257 DeinitCoverageLog();
258 #endif
259 }
254 260
255 void Assembler::GetCode(CodeDesc* desc) { 261 void Assembler::GetCode(CodeDesc* desc) {
256 // Finalize code (at this point overflow() may be true, but the gap ensures 262 // Finalize code (at this point overflow() may be true, but the gap ensures
257 // that we are still not overlapping instructions and relocation info). 263 // that we are still not overlapping instructions and relocation info).
258 ASSERT(pc_ <= reloc_info_writer.pos()); // No overlap. 264 ASSERT(pc_ <= reloc_info_writer.pos()); // No overlap.
259 // Set up code descriptor. 265 // Set up code descriptor.
260 desc->buffer = buffer_; 266 desc->buffer = buffer_;
261 desc->buffer_size = buffer_size_; 267 desc->buffer_size = buffer_size_;
262 desc->instr_size = pc_offset(); 268 desc->instr_size = pc_offset();
263 desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos(); 269 desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos();
(...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 return; 2004 return;
1999 } 2005 }
2000 2006
2001 2007
2002 #ifdef GENERATED_CODE_COVERAGE 2008 #ifdef GENERATED_CODE_COVERAGE
2003 static FILE* coverage_log = NULL; 2009 static FILE* coverage_log = NULL;
2004 2010
2005 2011
2006 static void InitCoverageLog() { 2012 static void InitCoverageLog() {
2007 char* file_name = getenv("V8_GENERATED_CODE_COVERAGE_LOG"); 2013 char* file_name = getenv("V8_GENERATED_CODE_COVERAGE_LOG");
2008 if (file_name != NULL) { 2014 if (file_name != NULL && NULL == coverage_log) {
2009 coverage_log = fopen(file_name, "aw+"); 2015 coverage_log = fopen(file_name, "aw+");
2010 } 2016 }
2011 } 2017 }
2012 2018
2019 static void DeinitCoverageLog() {
2020 if (coverage_log != NULL) {
2021 fclose(coverage_log);
2022 coverage_log = NULL;
2023 }
2024 }
2013 2025
2014 void LogGeneratedCodeCoverage(const char* file_line) { 2026 void LogGeneratedCodeCoverage(const char* file_line) {
2015 const char* return_address = (&file_line)[-1]; 2027 const char* return_address = (&file_line)[-1];
2016 char* push_insn = const_cast<char*>(return_address - 12); 2028 char* push_insn = const_cast<char*>(return_address - 12);
2017 push_insn[0] = 0xeb; // Relative branch insn. 2029 push_insn[0] = 0xeb; // Relative branch insn.
2018 push_insn[1] = 13; // Skip over coverage insns. 2030 push_insn[1] = 13; // Skip over coverage insns.
2019 if (coverage_log != NULL) { 2031 if (coverage_log != NULL) {
2020 fprintf(coverage_log, "%s\n", file_line); 2032 fprintf(coverage_log, "%s\n", file_line);
2021 fflush(coverage_log); 2033 fflush(coverage_log);
2022 } 2034 }
2023 } 2035 }
2024 2036
2025 #endif 2037 #endif
2026 2038
2027 } } // namespace v8::internal 2039 } } // namespace v8::internal
2028 2040
2029 #endif // V8_TARGET_ARCH_X87 2041 #endif // V8_TARGET_ARCH_X87
OLDNEW
« no previous file with comments | « src/x87/assembler-x87.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698