src/share/vm/memory/allocation.cpp

changeset 5241
f75faf51e8c4
parent 4295
59c790074993
child 5246
4b52137b07c9
     1.1 --- a/src/share/vm/memory/allocation.cpp	Wed Apr 17 10:12:42 2013 -0700
     1.2 +++ b/src/share/vm/memory/allocation.cpp	Thu Mar 07 11:49:38 2013 -0500
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -248,7 +248,7 @@
    1.11     ChunkPool(size_t size) : _size(size) { _first = NULL; _num_chunks = _num_used = 0; }
    1.12  
    1.13    // Allocate a new chunk from the pool (might expand the pool)
    1.14 -  _NOINLINE_ void* allocate(size_t bytes) {
    1.15 +  _NOINLINE_ void* allocate(size_t bytes, AllocFailType alloc_failmode) {
    1.16      assert(bytes == _size, "bad size");
    1.17      void* p = NULL;
    1.18      // No VM lock can be taken inside ThreadCritical lock, so os::malloc
    1.19 @@ -258,9 +258,9 @@
    1.20        p = get_first();
    1.21      }
    1.22      if (p == NULL) p = os::malloc(bytes, mtChunk, CURRENT_PC);
    1.23 -    if (p == NULL)
    1.24 +    if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) {
    1.25        vm_exit_out_of_memory(bytes, "ChunkPool::allocate");
    1.26 -
    1.27 +    }
    1.28      return p;
    1.29    }
    1.30  
    1.31 @@ -357,7 +357,7 @@
    1.32  //--------------------------------------------------------------------------------------
    1.33  // Chunk implementation
    1.34  
    1.35 -void* Chunk::operator new(size_t requested_size, size_t length) {
    1.36 +void* Chunk::operator new (size_t requested_size, AllocFailType alloc_failmode, size_t length) {
    1.37    // requested_size is equal to sizeof(Chunk) but in order for the arena
    1.38    // allocations to come out aligned as expected the size must be aligned
    1.39    // to expected arean alignment.
    1.40 @@ -365,13 +365,14 @@
    1.41    assert(ARENA_ALIGN(requested_size) == aligned_overhead_size(), "Bad alignment");
    1.42    size_t bytes = ARENA_ALIGN(requested_size) + length;
    1.43    switch (length) {
    1.44 -   case Chunk::size:        return ChunkPool::large_pool()->allocate(bytes);
    1.45 -   case Chunk::medium_size: return ChunkPool::medium_pool()->allocate(bytes);
    1.46 -   case Chunk::init_size:   return ChunkPool::small_pool()->allocate(bytes);
    1.47 +   case Chunk::size:        return ChunkPool::large_pool()->allocate(bytes, alloc_failmode);
    1.48 +   case Chunk::medium_size: return ChunkPool::medium_pool()->allocate(bytes, alloc_failmode);
    1.49 +   case Chunk::init_size:   return ChunkPool::small_pool()->allocate(bytes, alloc_failmode);
    1.50     default: {
    1.51 -     void *p =  os::malloc(bytes, mtChunk, CALLER_PC);
    1.52 -     if (p == NULL)
    1.53 +     void* p = os::malloc(bytes, mtChunk, CALLER_PC);
    1.54 +     if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) {
    1.55         vm_exit_out_of_memory(bytes, "Chunk::new");
    1.56 +     }
    1.57       return p;
    1.58     }
    1.59    }
    1.60 @@ -425,7 +426,7 @@
    1.61  Arena::Arena(size_t init_size) {
    1.62    size_t round_size = (sizeof (char *)) - 1;
    1.63    init_size = (init_size+round_size) & ~round_size;
    1.64 -  _first = _chunk = new (init_size) Chunk(init_size);
    1.65 +  _first = _chunk = new (AllocFailStrategy::EXIT_OOM, init_size) Chunk(init_size);
    1.66    _hwm = _chunk->bottom();      // Save the cached hwm, max
    1.67    _max = _chunk->top();
    1.68    set_size_in_bytes(init_size);
    1.69 @@ -433,7 +434,7 @@
    1.70  }
    1.71  
    1.72  Arena::Arena() {
    1.73 -  _first = _chunk = new (Chunk::init_size) Chunk(Chunk::init_size);
    1.74 +  _first = _chunk = new (AllocFailStrategy::EXIT_OOM, Chunk::init_size) Chunk(Chunk::init_size);
    1.75    _hwm = _chunk->bottom();      // Save the cached hwm, max
    1.76    _max = _chunk->top();
    1.77    set_size_in_bytes(Chunk::init_size);
    1.78 @@ -540,12 +541,9 @@
    1.79    size_t len = MAX2(x, (size_t) Chunk::size);
    1.80  
    1.81    Chunk *k = _chunk;            // Get filled-up chunk address
    1.82 -  _chunk = new (len) Chunk(len);
    1.83 +  _chunk = new (alloc_failmode, len) Chunk(len);
    1.84  
    1.85    if (_chunk == NULL) {
    1.86 -    if (alloc_failmode == AllocFailStrategy::EXIT_OOM) {
    1.87 -      signal_out_of_memory(len * Chunk::aligned_overhead_size(), "Arena::grow");
    1.88 -    }
    1.89      return NULL;
    1.90    }
    1.91    if (k) k->set_next(_chunk);   // Append new chunk to end of linked list

mercurial