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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 305 |
306 // Emit a single byte. Must always be inlined. | 306 // Emit a single byte. Must always be inlined. |
307 #define EMIT(x) \ | 307 #define EMIT(x) \ |
308 *pc_++ = (x) | 308 *pc_++ = (x) |
309 | 309 |
310 | 310 |
311 #ifdef GENERATED_CODE_COVERAGE | 311 #ifdef GENERATED_CODE_COVERAGE |
312 static void InitCoverageLog(); | 312 static void InitCoverageLog(); |
313 #endif | 313 #endif |
314 | 314 |
315 Assembler::Assembler(Isolate* arg_isolate, void* buffer, int buffer_size) | 315 Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size) |
316 : AssemblerBase(arg_isolate), | 316 : AssemblerBase(isolate, buffer, buffer_size), |
317 positions_recorder_(this) { | 317 positions_recorder_(this) { |
318 if (buffer == NULL) { | |
319 // Do our own buffer management. | |
320 if (buffer_size <= kMinimalBufferSize) { | |
321 buffer_size = kMinimalBufferSize; | |
322 | |
323 if (isolate()->assembler_spare_buffer() != NULL) { | |
324 buffer = isolate()->assembler_spare_buffer(); | |
325 isolate()->set_assembler_spare_buffer(NULL); | |
326 } | |
327 } | |
328 if (buffer == NULL) { | |
329 buffer_ = NewArray<byte>(buffer_size); | |
330 } else { | |
331 buffer_ = static_cast<byte*>(buffer); | |
332 } | |
333 buffer_size_ = buffer_size; | |
334 own_buffer_ = true; | |
335 } else { | |
336 // Use externally provided buffer instead. | |
337 ASSERT(buffer_size > 0); | |
338 buffer_ = static_cast<byte*>(buffer); | |
339 buffer_size_ = buffer_size; | |
340 own_buffer_ = false; | |
341 } | |
342 | |
343 // Clear the buffer in debug mode unless it was provided by the | 318 // Clear the buffer in debug mode unless it was provided by the |
344 // caller in which case we can't be sure it's okay to overwrite | 319 // caller in which case we can't be sure it's okay to overwrite |
345 // existing code in it; see CodePatcher::CodePatcher(...). | 320 // existing code in it; see CodePatcher::CodePatcher(...). |
346 #ifdef DEBUG | 321 #ifdef DEBUG |
347 if (own_buffer_) { | 322 if (own_buffer_) { |
348 memset(buffer_, 0xCC, buffer_size); // int3 | 323 memset(buffer_, 0xCC, buffer_size_); // int3 |
349 } | 324 } |
350 #endif | 325 #endif |
351 | 326 |
352 // Set up buffer pointers. | 327 reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_); |
353 ASSERT(buffer_ != NULL); | |
354 pc_ = buffer_; | |
355 reloc_info_writer.Reposition(buffer_ + buffer_size, pc_); | |
356 | 328 |
357 #ifdef GENERATED_CODE_COVERAGE | 329 #ifdef GENERATED_CODE_COVERAGE |
358 InitCoverageLog(); | 330 InitCoverageLog(); |
359 #endif | 331 #endif |
360 } | 332 } |
361 | 333 |
362 | 334 |
363 Assembler::~Assembler() { | |
364 if (own_buffer_) { | |
365 if (isolate()->assembler_spare_buffer() == NULL && | |
366 buffer_size_ == kMinimalBufferSize) { | |
367 isolate()->set_assembler_spare_buffer(buffer_); | |
368 } else { | |
369 DeleteArray(buffer_); | |
370 } | |
371 } | |
372 } | |
373 | |
374 | |
375 void Assembler::GetCode(CodeDesc* desc) { | 335 void Assembler::GetCode(CodeDesc* desc) { |
376 // Finalize code (at this point overflow() may be true, but the gap ensures | 336 // Finalize code (at this point overflow() may be true, but the gap ensures |
377 // that we are still not overlapping instructions and relocation info). | 337 // that we are still not overlapping instructions and relocation info). |
378 ASSERT(pc_ <= reloc_info_writer.pos()); // No overlap. | 338 ASSERT(pc_ <= reloc_info_writer.pos()); // No overlap. |
379 // Set up code descriptor. | 339 // Set up code descriptor. |
380 desc->buffer = buffer_; | 340 desc->buffer = buffer_; |
381 desc->buffer_size = buffer_size_; | 341 desc->buffer_size = buffer_size_; |
382 desc->instr_size = pc_offset(); | 342 desc->instr_size = pc_offset(); |
383 desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos(); | 343 desc->reloc_size = (buffer_ + buffer_size_) - reloc_info_writer.pos(); |
384 desc->origin = this; | 344 desc->origin = this; |
(...skipping 2279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2664 fprintf(coverage_log, "%s\n", file_line); | 2624 fprintf(coverage_log, "%s\n", file_line); |
2665 fflush(coverage_log); | 2625 fflush(coverage_log); |
2666 } | 2626 } |
2667 } | 2627 } |
2668 | 2628 |
2669 #endif | 2629 #endif |
2670 | 2630 |
2671 } } // namespace v8::internal | 2631 } } // namespace v8::internal |
2672 | 2632 |
2673 #endif // V8_TARGET_ARCH_IA32 | 2633 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |