hotspot/src/share/vm/memory/allocation.inline.hpp
author david
Tue, 29 Sep 2015 11:02:08 +0200
changeset 33105 294e48b4f704
parent 30293 2bb164446d67
child 37057 03b3e1870228
permissions -rw-r--r--
8080775: Better argument formatting for assert() and friends Reviewed-by: kbarrett, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
15855
2ac9ebea17f3 8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents: 14083
diff changeset
    28
#include "runtime/atomic.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "runtime/os.hpp"
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    30
#include "services/memTracker.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    31
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// Explicit C-heap memory management
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
void trace_heap_malloc(size_t size, const char* name, void *p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
void trace_heap_free(void *p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
8325
cc62dbe71e6a 7018849: 7017124 fix broke VM build on some platforms
kvn
parents: 8320
diff changeset
    37
#ifndef PRODUCT
8320
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7397
diff changeset
    38
// Increments unsigned long value for statistics (not atomic on MP).
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7397
diff changeset
    39
inline void inc_stat_counter(volatile julong* dest, julong add_value) {
8325
cc62dbe71e6a 7018849: 7017124 fix broke VM build on some platforms
kvn
parents: 8320
diff changeset
    40
#if defined(SPARC) || defined(X86)
cc62dbe71e6a 7018849: 7017124 fix broke VM build on some platforms
kvn
parents: 8320
diff changeset
    41
  // Sparc and X86 have atomic jlong (8 bytes) instructions
8320
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7397
diff changeset
    42
  julong value = Atomic::load((volatile jlong*)dest);
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7397
diff changeset
    43
  value += add_value;
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7397
diff changeset
    44
  Atomic::store((jlong)value, (volatile jlong*)dest);
8325
cc62dbe71e6a 7018849: 7017124 fix broke VM build on some platforms
kvn
parents: 8320
diff changeset
    45
#else
cc62dbe71e6a 7018849: 7017124 fix broke VM build on some platforms
kvn
parents: 8320
diff changeset
    46
  // possible word-tearing during load/store
cc62dbe71e6a 7018849: 7017124 fix broke VM build on some platforms
kvn
parents: 8320
diff changeset
    47
  *dest += add_value;
cc62dbe71e6a 7018849: 7017124 fix broke VM build on some platforms
kvn
parents: 8320
diff changeset
    48
#endif
8320
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7397
diff changeset
    49
}
8325
cc62dbe71e6a 7018849: 7017124 fix broke VM build on some platforms
kvn
parents: 8320
diff changeset
    50
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// allocate using malloc; will fail if no memory available
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    53
inline char* AllocateHeap(size_t size, MEMFLAGS flags,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    54
    const NativeCallStack& stack,
14083
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13963
diff changeset
    55
    AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    56
  char* p = (char*) os::malloc(size, flags, stack);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  #ifdef ASSERT
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    58
  if (PrintMallocFree) trace_heap_malloc(size, "AllocateHeap", p);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  #endif
17087
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 17031
diff changeset
    60
  if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) {
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 17031
diff changeset
    61
    vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "AllocateHeap");
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 17031
diff changeset
    62
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    63
  return p;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    64
}
30293
2bb164446d67 8076212: AllocateHeap() and ReallocateHeap() should be inlined.
ysuenaga
parents: 27880
diff changeset
    65
2bb164446d67 8076212: AllocateHeap() and ReallocateHeap() should be inlined.
ysuenaga
parents: 27880
diff changeset
    66
#ifdef __GNUC__
2bb164446d67 8076212: AllocateHeap() and ReallocateHeap() should be inlined.
ysuenaga
parents: 27880
diff changeset
    67
__attribute__((always_inline))
2bb164446d67 8076212: AllocateHeap() and ReallocateHeap() should be inlined.
ysuenaga
parents: 27880
diff changeset
    68
#endif
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    69
inline char* AllocateHeap(size_t size, MEMFLAGS flags,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    70
    AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    71
  return AllocateHeap(size, flags, CURRENT_PC, alloc_failmode);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    72
}
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    73
30293
2bb164446d67 8076212: AllocateHeap() and ReallocateHeap() should be inlined.
ysuenaga
parents: 27880
diff changeset
    74
#ifdef __GNUC__
2bb164446d67 8076212: AllocateHeap() and ReallocateHeap() should be inlined.
ysuenaga
parents: 27880
diff changeset
    75
__attribute__((always_inline))
2bb164446d67 8076212: AllocateHeap() and ReallocateHeap() should be inlined.
ysuenaga
parents: 27880
diff changeset
    76
#endif
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    77
inline char* ReallocateHeap(char *old, size_t size, MEMFLAGS flag,
14083
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13963
diff changeset
    78
    AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    79
  char* p = (char*) os::realloc(old, size, flag, CURRENT_PC);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    80
  #ifdef ASSERT
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    81
  if (PrintMallocFree) trace_heap_malloc(size, "ReallocateHeap", p);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    82
  #endif
17087
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 17031
diff changeset
    83
  if (p == NULL && alloc_failmode == AllocFailStrategy::EXIT_OOM) {
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 17031
diff changeset
    84
    vm_exit_out_of_memory(size, OOM_MALLOC_ERROR, "ReallocateHeap");
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 17031
diff changeset
    85
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 25946
diff changeset
    89
inline void FreeHeap(void* p) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  if (PrintMallocFree) trace_heap_free(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  #endif
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 25946
diff changeset
    93
  os::free(p);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
}
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    95
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    96
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    97
template <MEMFLAGS F> void* CHeapObj<F>::operator new(size_t size,
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    98
      const NativeCallStack& stack) throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    99
  void* p = (void*)AllocateHeap(size, F, stack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   100
#ifdef ASSERT
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   101
  if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   102
#endif
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   103
  return p;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   104
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   105
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   106
template <MEMFLAGS F> void* CHeapObj<F>::operator new(size_t size) throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   107
  return CHeapObj<F>::operator new(size, CALLER_PC);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   108
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   109
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   110
template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   111
  const std::nothrow_t&  nothrow_constant, const NativeCallStack& stack) throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   112
  void* p = (void*)AllocateHeap(size, F, stack,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   113
      AllocFailStrategy::RETURN_NULL);
17031
9a576749065b 8012907: anti-delta fix for 8010992
dcubed
parents: 17026
diff changeset
   114
#ifdef ASSERT
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   115
    if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p);
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   116
#endif
17031
9a576749065b 8012907: anti-delta fix for 8010992
dcubed
parents: 17026
diff changeset
   117
    return p;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   118
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   119
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   120
template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size,
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   121
  const std::nothrow_t& nothrow_constant) throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   122
  return CHeapObj<F>::operator new(size, nothrow_constant, CALLER_PC);
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   123
}
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   124
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   125
template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size,
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   126
      const NativeCallStack& stack) throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   127
  return CHeapObj<F>::operator new(size, stack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   128
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   129
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   130
template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size)
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   131
  throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   132
  return CHeapObj<F>::operator new(size, CALLER_PC);
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   133
}
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   134
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   135
template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size,
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   136
  const std::nothrow_t&  nothrow_constant, const NativeCallStack& stack) throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   137
  return CHeapObj<F>::operator new(size, nothrow_constant, stack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   138
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   139
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   140
template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   141
  const std::nothrow_t& nothrow_constant) throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   142
  return CHeapObj<F>::operator new(size, nothrow_constant, CALLER_PC);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   143
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   144
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   145
template <MEMFLAGS F> void CHeapObj<F>::operator delete(void* p){
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 25946
diff changeset
   146
    FreeHeap(p);
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   147
}
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   148
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   149
template <MEMFLAGS F> void CHeapObj<F>::operator delete [](void* p){
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 25946
diff changeset
   150
    FreeHeap(p);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   151
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   152
16682
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   153
template <class E, MEMFLAGS F>
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   154
char* ArrayAllocator<E, F>::allocate_inner(size_t &size, bool &use_malloc) {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   155
  char* addr = NULL;
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   156
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   157
  if (use_malloc) {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   158
    addr = AllocateHeap(size, F);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   159
    if (addr == NULL && size >= (size_t)os::vm_allocation_granularity()) {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   160
      // malloc failed let's try with mmap instead
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   161
      use_malloc = false;
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   162
    } else {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   163
      return addr;
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   164
    }
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   165
  }
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   166
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   167
  int alignment = os::vm_allocation_granularity();
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   168
  size = align_size_up(size, alignment);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   169
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   170
  addr = os::reserve_memory(size, NULL, alignment, F);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   171
  if (addr == NULL) {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   172
    vm_exit_out_of_memory(size, OOM_MMAP_ERROR, "Allocator (reserve)");
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   173
  }
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   174
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   175
  os::commit_memory_or_exit(addr, size, !ExecMem, "Allocator (commit)");
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   176
  return addr;
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   177
}
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   178
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   179
template <class E, MEMFLAGS F>
16682
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   180
E* ArrayAllocator<E, F>::allocate(size_t length) {
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   181
  assert(_addr == NULL, "Already in use");
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   182
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   183
  _size = sizeof(E) * length;
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   184
  _use_malloc = should_use_malloc(_size);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   185
  _addr = allocate_inner(_size, _use_malloc);
16682
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   186
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   187
  return (E*)_addr;
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   188
}
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   189
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   190
template <class E, MEMFLAGS F>
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   191
E* ArrayAllocator<E, F>::reallocate(size_t new_length) {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   192
  size_t new_size = sizeof(E) * new_length;
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   193
  bool use_malloc = should_use_malloc(new_size);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   194
  char* new_addr = allocate_inner(new_size, use_malloc);
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   195
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   196
  memcpy(new_addr, _addr, MIN2(new_size, _size));
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   197
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   198
  free();
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   199
  _size = new_size;
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   200
  _use_malloc = use_malloc;
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   201
  _addr = new_addr;
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   202
  return (E*)new_addr;
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   203
}
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   204
16682
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   205
template<class E, MEMFLAGS F>
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   206
void ArrayAllocator<E, F>::free() {
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   207
  if (_addr != NULL) {
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   208
    if (_use_malloc) {
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 25946
diff changeset
   209
      FreeHeap(_addr);
16682
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   210
    } else {
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   211
      os::release_memory(_addr, _size);
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   212
    }
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   213
    _addr = NULL;
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   214
  }
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   215
}
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   216
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   217
#endif // SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP