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 mem = OS::Allocate(requested, allocated, true); | 383 mem = OS::Allocate(requested + Page::kPageSize, allocated, true); |
384 OS::Guard(mem, Page::kPageSize); | |
Vyacheslav Egorov (Chromium)
2011/07/15 11:59:14
You have decreased kPagesPerChunk for all spaces b
Cris Neckar
2011/07/15 18:51:29
Done.
| |
385 *allocated -= Page::kPageSize; | |
386 mem = static_cast<char*>(mem) + Page::kPageSize; | |
Vyacheslav Egorov (Chromium)
2011/07/15 11:59:14
we use Address type instead of char* in such cases
Cris Neckar
2011/07/15 18:51:29
Done.
| |
384 } | 387 } |
385 // Update executable memory size. | 388 // Update executable memory size. |
386 size_executable_ += static_cast<int>(*allocated); | 389 size_executable_ += static_cast<int>(*allocated); |
387 } else { | 390 } else { |
388 mem = OS::Allocate(requested, allocated, false); | 391 mem = OS::Allocate(requested, allocated, false); |
389 } | 392 } |
390 int alloced = static_cast<int>(*allocated); | 393 int alloced = static_cast<int>(*allocated); |
391 size_ += alloced; | 394 size_ += alloced; |
392 | 395 |
393 #ifdef DEBUG | 396 #ifdef DEBUG |
394 ZapBlock(reinterpret_cast<Address>(mem), alloced); | 397 ZapBlock(reinterpret_cast<Address>(mem), alloced); |
395 #endif | 398 #endif |
396 isolate_->counters()->memory_allocated()->Increment(alloced); | 399 isolate_->counters()->memory_allocated()->Increment(alloced); |
397 return mem; | 400 return mem; |
398 } | 401 } |
399 | 402 |
400 | 403 |
401 void MemoryAllocator::FreeRawMemory(void* mem, | 404 void MemoryAllocator::FreeRawMemory(void* mem, |
402 size_t length, | 405 size_t length, |
403 Executability executable) { | 406 Executability executable) { |
404 #ifdef DEBUG | 407 #ifdef DEBUG |
405 ZapBlock(reinterpret_cast<Address>(mem), length); | 408 ZapBlock(reinterpret_cast<Address>(mem), length); |
406 #endif | 409 #endif |
407 if (isolate_->code_range()->contains(static_cast<Address>(mem))) { | 410 if (isolate_->code_range()->contains(static_cast<Address>(mem))) { |
408 isolate_->code_range()->FreeRawMemory(mem, length); | 411 isolate_->code_range()->FreeRawMemory(mem, length); |
409 } else { | 412 } else { |
410 OS::Free(mem, length); | 413 size_t guardsize = (executable == EXECUTABLE) ? Page::kPageSize : 0; |
414 OS::Free(static_cast<char*>(mem) - guardsize, length + guardsize); | |
Vyacheslav Egorov (Chromium)
2011/07/15 11:59:14
we use Address type instead of char* in such cases
Cris Neckar
2011/07/15 18:51:29
Done.
| |
411 } | 415 } |
412 isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(length)); | 416 isolate_->counters()->memory_allocated()->Decrement(static_cast<int>(length)); |
413 size_ -= static_cast<int>(length); | 417 size_ -= static_cast<int>(length); |
414 if (executable == EXECUTABLE) size_executable_ -= static_cast<int>(length); | 418 if (executable == EXECUTABLE) size_executable_ -= static_cast<int>(length); |
415 | 419 |
416 ASSERT(size_ >= 0); | 420 ASSERT(size_ >= 0); |
417 ASSERT(size_executable_ >= 0); | 421 ASSERT(size_executable_ >= 0); |
418 } | 422 } |
419 | 423 |
420 | 424 |
(...skipping 2636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3057 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) { | 3061 for (HeapObject* obj = obj_it.next(); obj != NULL; obj = obj_it.next()) { |
3058 if (obj->IsCode()) { | 3062 if (obj->IsCode()) { |
3059 Code* code = Code::cast(obj); | 3063 Code* code = Code::cast(obj); |
3060 isolate->code_kind_statistics()[code->kind()] += code->Size(); | 3064 isolate->code_kind_statistics()[code->kind()] += code->Size(); |
3061 } | 3065 } |
3062 } | 3066 } |
3063 } | 3067 } |
3064 #endif // DEBUG | 3068 #endif // DEBUG |
3065 | 3069 |
3066 } } // namespace v8::internal | 3070 } } // namespace v8::internal |
OLD | NEW |