| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 } | 339 } |
| 340 | 340 |
| 341 | 341 |
| 342 // ----------------------------------------------------------------------------- | 342 // ----------------------------------------------------------------------------- |
| 343 // Implementation of Assembler. | 343 // Implementation of Assembler. |
| 344 | 344 |
| 345 #ifdef GENERATED_CODE_COVERAGE | 345 #ifdef GENERATED_CODE_COVERAGE |
| 346 static void InitCoverageLog(); | 346 static void InitCoverageLog(); |
| 347 #endif | 347 #endif |
| 348 | 348 |
| 349 Assembler::Assembler(Isolate* arg_isolate, void* buffer, int buffer_size) | 349 Assembler::Assembler(Isolate* isolate, void* buffer, int buffer_size) |
| 350 : AssemblerBase(arg_isolate), | 350 : AssemblerBase(isolate, buffer, buffer_size), |
| 351 code_targets_(100), | 351 code_targets_(100), |
| 352 positions_recorder_(this) { | 352 positions_recorder_(this) { |
| 353 if (buffer == NULL) { | |
| 354 // Do our own buffer management. | |
| 355 if (buffer_size <= kMinimalBufferSize) { | |
| 356 buffer_size = kMinimalBufferSize; | |
| 357 | |
| 358 if (isolate() != NULL && isolate()->assembler_spare_buffer() != NULL) { | |
| 359 buffer = isolate()->assembler_spare_buffer(); | |
| 360 isolate()->set_assembler_spare_buffer(NULL); | |
| 361 } | |
| 362 } | |
| 363 if (buffer == NULL) { | |
| 364 buffer_ = NewArray<byte>(buffer_size); | |
| 365 } else { | |
| 366 buffer_ = static_cast<byte*>(buffer); | |
| 367 } | |
| 368 buffer_size_ = buffer_size; | |
| 369 own_buffer_ = true; | |
| 370 } else { | |
| 371 // Use externally provided buffer instead. | |
| 372 ASSERT(buffer_size > 0); | |
| 373 buffer_ = static_cast<byte*>(buffer); | |
| 374 buffer_size_ = buffer_size; | |
| 375 own_buffer_ = false; | |
| 376 } | |
| 377 | |
| 378 // Clear the buffer in debug mode unless it was provided by the | 353 // Clear the buffer in debug mode unless it was provided by the |
| 379 // caller in which case we can't be sure it's okay to overwrite | 354 // caller in which case we can't be sure it's okay to overwrite |
| 380 // existing code in it. | 355 // existing code in it. |
| 381 #ifdef DEBUG | 356 #ifdef DEBUG |
| 382 if (own_buffer_) { | 357 if (own_buffer_) { |
| 383 memset(buffer_, 0xCC, buffer_size); // int3 | 358 memset(buffer_, 0xCC, buffer_size_); // int3 |
| 384 } | 359 } |
| 385 #endif | 360 #endif |
| 386 | 361 |
| 387 // Set up buffer pointers. | 362 reloc_info_writer.Reposition(buffer_ + buffer_size_, pc_); |
| 388 ASSERT(buffer_ != NULL); | |
| 389 pc_ = buffer_; | |
| 390 reloc_info_writer.Reposition(buffer_ + buffer_size, pc_); | |
| 391 | 363 |
| 392 | 364 |
| 393 #ifdef GENERATED_CODE_COVERAGE | 365 #ifdef GENERATED_CODE_COVERAGE |
| 394 InitCoverageLog(); | 366 InitCoverageLog(); |
| 395 #endif | 367 #endif |
| 396 } | 368 } |
| 397 | 369 |
| 398 | 370 |
| 399 Assembler::~Assembler() { | |
| 400 if (own_buffer_) { | |
| 401 if (isolate() != NULL && | |
| 402 isolate()->assembler_spare_buffer() == NULL && | |
| 403 buffer_size_ == kMinimalBufferSize) { | |
| 404 isolate()->set_assembler_spare_buffer(buffer_); | |
| 405 } else { | |
| 406 DeleteArray(buffer_); | |
| 407 } | |
| 408 } | |
| 409 } | |
| 410 | |
| 411 | |
| 412 void Assembler::GetCode(CodeDesc* desc) { | 371 void Assembler::GetCode(CodeDesc* desc) { |
| 413 // Finalize code (at this point overflow() may be true, but the gap ensures | 372 // Finalize code (at this point overflow() may be true, but the gap ensures |
| 414 // that we are still not overlapping instructions and relocation info). | 373 // that we are still not overlapping instructions and relocation info). |
| 415 ASSERT(pc_ <= reloc_info_writer.pos()); // No overlap. | 374 ASSERT(pc_ <= reloc_info_writer.pos()); // No overlap. |
| 416 // Set up code descriptor. | 375 // Set up code descriptor. |
| 417 desc->buffer = buffer_; | 376 desc->buffer = buffer_; |
| 418 desc->buffer_size = buffer_size_; | 377 desc->buffer_size = buffer_size_; |
| 419 desc->instr_size = pc_offset(); | 378 desc->instr_size = pc_offset(); |
| 420 ASSERT(desc->instr_size > 0); // Zero-size code objects upset the system. | 379 ASSERT(desc->instr_size > 0); // Zero-size code objects upset the system. |
| 421 desc->reloc_size = | 380 desc->reloc_size = |
| (...skipping 2630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3052 bool RelocInfo::IsCodedSpecially() { | 3011 bool RelocInfo::IsCodedSpecially() { |
| 3053 // The deserializer needs to know whether a pointer is specially coded. Being | 3012 // The deserializer needs to know whether a pointer is specially coded. Being |
| 3054 // specially coded on x64 means that it is a relative 32 bit address, as used | 3013 // specially coded on x64 means that it is a relative 32 bit address, as used |
| 3055 // by branch instructions. | 3014 // by branch instructions. |
| 3056 return (1 << rmode_) & kApplyMask; | 3015 return (1 << rmode_) & kApplyMask; |
| 3057 } | 3016 } |
| 3058 | 3017 |
| 3059 } } // namespace v8::internal | 3018 } } // namespace v8::internal |
| 3060 | 3019 |
| 3061 #endif // V8_TARGET_ARCH_X64 | 3020 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |