| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 LOG(isolate_, | 373 LOG(isolate_, |
| 374 StringEvent("MemoryAllocator::AllocateRawMemory", | 374 StringEvent("MemoryAllocator::AllocateRawMemory", |
| 375 "V8 Executable Allocation capacity exceeded")); | 375 "V8 Executable Allocation capacity exceeded")); |
| 376 return NULL; | 376 return NULL; |
| 377 } | 377 } |
| 378 // Allocate executable memory either from code range or from the | 378 // Allocate executable memory either from code range or from the |
| 379 // OS. | 379 // OS. |
| 380 if (isolate_->code_range()->exists()) { | 380 if (isolate_->code_range()->exists()) { |
| 381 mem = isolate_->code_range()->AllocateRawMemory(requested, allocated); | 381 mem = isolate_->code_range()->AllocateRawMemory(requested, allocated); |
| 382 } else { | 382 } else { |
| 383 #ifdef ENABLE_HEAP_PROTECTION |
| 384 mem = OS::Allocate(requested + Page::kPageSize, allocated, true); |
| 385 OS::Guard(mem, Page::kPageSize); |
| 386 *allocated -= Page::kPageSize; |
| 387 mem = static_cast<char*>(mem) + Page::kPageSize; |
| 388 #else // ENABLE_HEAP_PROTECTION |
| 383 mem = OS::Allocate(requested, allocated, true); | 389 mem = OS::Allocate(requested, allocated, true); |
| 390 #endif // ENABLE_HEAP_PROTECTION |
| 384 } | 391 } |
| 385 // Update executable memory size. | 392 // Update executable memory size. |
| 386 size_executable_ += static_cast<int>(*allocated); | 393 size_executable_ += static_cast<int>(*allocated); |
| 387 } else { | 394 } else { |
| 388 mem = OS::Allocate(requested, allocated, false); | 395 mem = OS::Allocate(requested, allocated, false); |
| 389 } | 396 } |
| 390 int alloced = static_cast<int>(*allocated); | 397 int alloced = static_cast<int>(*allocated); |
| 391 size_ += alloced; | 398 size_ += alloced; |
| 392 | 399 |
| 393 #ifdef DEBUG | 400 #ifdef DEBUG |
| 394 ZapBlock(reinterpret_cast<Address>(mem), alloced); | 401 ZapBlock(reinterpret_cast<Address>(mem), alloced); |
| 395 #endif | 402 #endif |
| 396 isolate_->counters()->memory_allocated()->Increment(alloced); | 403 isolate_->counters()->memory_allocated()->Increment(alloced); |
| 397 return mem; | 404 return mem; |
| 398 } | 405 } |
| 399 | 406 |
| 400 | 407 |
| 401 void MemoryAllocator::FreeRawMemory(void* mem, | 408 void MemoryAllocator::FreeRawMemory(void* mem, |
| 402 size_t length, | 409 size_t length, |
| 403 Executability executable) { | 410 Executability executable) { |
| 404 #ifdef DEBUG | 411 #ifdef DEBUG |
| 405 ZapBlock(reinterpret_cast<Address>(mem), length); | 412 ZapBlock(reinterpret_cast<Address>(mem), length); |
| 406 #endif | 413 #endif |
| 407 if (isolate_->code_range()->contains(static_cast<Address>(mem))) { | 414 if (isolate_->code_range()->contains(static_cast<Address>(mem))) { |
| 408 isolate_->code_range()->FreeRawMemory(mem, length); | 415 isolate_->code_range()->FreeRawMemory(mem, length); |
| 409 } else { | 416 } else { |
| 410 OS::Free(mem, length); | 417 #ifdef ENABLE_HEAP_PROTECTION |
| 418 size_t guardsize = (executable == EXECUTABLE) ? Page::kPageSize : 0; |
| 419 OS::Free(static_cast<char*>(mem) - guardsize, length + guardsize); |
| 420 #else // ENABLE_HEAP_PROTECTION |
| 421 OS::Free(static_cast<char*>(mem), length); |
| 422 #endif // ENABLE_HEAP_PROTECTION |
| 411 } | 423 } |
| 412 isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(length)); | 424 isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(length)); |
| 413 size_ -= static_cast<int>(length); | 425 size_ -= static_cast<int>(length); |
| 414 if (executable == EXECUTABLE) size_executable_ -= static_cast<int>(length); | 426 if (executable == EXECUTABLE) size_executable_ -= static_cast<int>(length); |
| 415 | 427 |
| 416 ASSERT(size_ >= 0); | 428 ASSERT(size_ >= 0); |
| 417 ASSERT(size_executable_ >= 0); | 429 ASSERT(size_executable_ >= 0); |
| 418 } | 430 } |
| 419 | 431 |
| 420 | 432 |
| (...skipping 2715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3136 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) { | 3148 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) { |
| 3137 if (obj->IsCode()) { | 3149 if (obj->IsCode()) { |
| 3138 Code* code = Code::cast(obj); | 3150 Code* code = Code::cast(obj); |
| 3139 isolate->code_kind_statistics()[code->kind()] += code->Size(); | 3151 isolate->code_kind_statistics()[code->kind()] += code->Size(); |
| 3140 } | 3152 } |
| 3141 } | 3153 } |
| 3142 } | 3154 } |
| 3143 #endif // DEBUG | 3155 #endif // DEBUG |
| 3144 | 3156 |
| 3145 } } // namespace v8::internal | 3157 } } // namespace v8::internal |
| OLD | NEW |