hotspot/src/share/vm/memory/allocation.inline.hpp
author tschatzl
Thu, 15 Sep 2016 16:44:19 +0200
changeset 41176 ff9f64534cff
parent 40655 9f644073d3a0
child 46619 a3919f5e8d2b
permissions -rw-r--r--
8159422: Very high Concurrent Mark mark stack contention Summary: Decrease contention on mark stack by splitting locks, and minimizing the amount of time these locks are held. Improve mark stack management. Reviewed-by: kbarrett, mgerdin, eosterlund
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39405
diff changeset
     2
 * Copyright (c) 1997, 2016, 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
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 39405
diff changeset
    28
#include "runtime/atomic.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"
39405
314741ca98d5 8153743: AllocateHeap() and ReallocateHeap() should use ALWAYSINLINE macro
ysuenaga
parents: 37096
diff changeset
    31
#include "utilities/globalDefinitions.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// Explicit C-heap memory management
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
void trace_heap_malloc(size_t size, const char* name, void *p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
void trace_heap_free(void *p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
8325
cc62dbe71e6a 7018849: 7017124 fix broke VM build on some platforms
kvn
parents: 8320
diff changeset
    38
#ifndef PRODUCT
8320
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7397
diff changeset
    39
// 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
    40
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
    41
#if defined(SPARC) || defined(X86)
cc62dbe71e6a 7018849: 7017124 fix broke VM build on some platforms
kvn
parents: 8320
diff changeset
    42
  // 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
    43
  julong value = Atomic::load((volatile jlong*)dest);
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7397
diff changeset
    44
  value += add_value;
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7397
diff changeset
    45
  Atomic::store((jlong)value, (volatile jlong*)dest);
8325
cc62dbe71e6a 7018849: 7017124 fix broke VM build on some platforms
kvn
parents: 8320
diff changeset
    46
#else
cc62dbe71e6a 7018849: 7017124 fix broke VM build on some platforms
kvn
parents: 8320
diff changeset
    47
  // possible word-tearing during load/store
cc62dbe71e6a 7018849: 7017124 fix broke VM build on some platforms
kvn
parents: 8320
diff changeset
    48
  *dest += add_value;
cc62dbe71e6a 7018849: 7017124 fix broke VM build on some platforms
kvn
parents: 8320
diff changeset
    49
#endif
8320
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7397
diff changeset
    50
}
8325
cc62dbe71e6a 7018849: 7017124 fix broke VM build on some platforms
kvn
parents: 8320
diff changeset
    51
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// allocate using malloc; will fail if no memory available
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    54
inline char* AllocateHeap(size_t size, MEMFLAGS flags,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    55
    const NativeCallStack& stack,
14083
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13963
diff changeset
    56
    AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    57
  char* p = (char*) os::malloc(size, flags, stack);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  #ifdef ASSERT
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    59
  if (PrintMallocFree) trace_heap_malloc(size, "AllocateHeap", p);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  #endif
17087
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 17031
diff changeset
    61
  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
    62
    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
    63
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    64
  return p;
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    65
}
30293
2bb164446d67 8076212: AllocateHeap() and ReallocateHeap() should be inlined.
ysuenaga
parents: 27880
diff changeset
    66
39405
314741ca98d5 8153743: AllocateHeap() and ReallocateHeap() should use ALWAYSINLINE macro
ysuenaga
parents: 37096
diff changeset
    67
ALWAYSINLINE char* AllocateHeap(size_t size, MEMFLAGS flags,
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    68
    AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    69
  return AllocateHeap(size, flags, CURRENT_PC, alloc_failmode);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    70
}
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    71
39405
314741ca98d5 8153743: AllocateHeap() and ReallocateHeap() should use ALWAYSINLINE macro
ysuenaga
parents: 37096
diff changeset
    72
ALWAYSINLINE 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
    73
    AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    74
  char* p = (char*) os::realloc(old, size, flag, CURRENT_PC);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    75
  #ifdef ASSERT
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    76
  if (PrintMallocFree) trace_heap_malloc(size, "ReallocateHeap", p);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    77
  #endif
17087
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 17031
diff changeset
    78
  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
    79
    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
    80
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  return p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 25946
diff changeset
    84
inline void FreeHeap(void* p) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  #ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  if (PrintMallocFree) trace_heap_free(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  #endif
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 25946
diff changeset
    88
  os::free(p);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
}
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    90
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    91
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
    92
template <MEMFLAGS F> void* CHeapObj<F>::operator new(size_t size,
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    93
      const NativeCallStack& stack) throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    94
  void* p = (void*)AllocateHeap(size, F, stack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    95
#ifdef ASSERT
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    96
  if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    97
#endif
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    98
  return p;
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
    99
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   100
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   101
template <MEMFLAGS F> void* CHeapObj<F>::operator new(size_t size) throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   102
  return CHeapObj<F>::operator new(size, CALLER_PC);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   103
}
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
template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   106
  const std::nothrow_t&  nothrow_constant, const NativeCallStack& stack) throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   107
  void* p = (void*)AllocateHeap(size, F, stack,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   108
      AllocFailStrategy::RETURN_NULL);
17031
9a576749065b 8012907: anti-delta fix for 8010992
dcubed
parents: 17026
diff changeset
   109
#ifdef ASSERT
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   110
    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
   111
#endif
17031
9a576749065b 8012907: anti-delta fix for 8010992
dcubed
parents: 17026
diff changeset
   112
    return p;
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   113
  }
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   114
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   115
template <MEMFLAGS F> void* CHeapObj<F>::operator new (size_t size,
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   116
  const std::nothrow_t& nothrow_constant) throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   117
  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
   118
}
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   119
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
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 NativeCallStack& stack) throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   122
  return CHeapObj<F>::operator new(size, stack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   123
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   124
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   125
template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size)
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   126
  throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   127
  return CHeapObj<F>::operator new(size, CALLER_PC);
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   128
}
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   129
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   130
template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size,
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   131
  const std::nothrow_t&  nothrow_constant, const NativeCallStack& stack) throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   132
  return CHeapObj<F>::operator new(size, nothrow_constant, stack);
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   133
}
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   134
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   135
template <MEMFLAGS F> void* CHeapObj<F>::operator new [](size_t size,
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   136
  const std::nothrow_t& nothrow_constant) throw() {
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 23545
diff changeset
   137
  return CHeapObj<F>::operator new(size, nothrow_constant, CALLER_PC);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   138
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   139
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   140
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
   141
    FreeHeap(p);
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   142
}
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   143
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17302
diff changeset
   144
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
   145
    FreeHeap(p);
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   146
}
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   147
16682
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   148
template <class E, MEMFLAGS F>
37096
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   149
size_t MmapArrayAllocator<E, F>::size_for(size_t length) {
37057
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   150
  size_t size = length * sizeof(E);
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   151
  int alignment = os::vm_allocation_granularity();
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   152
  return align_size_up(size, alignment);
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   153
}
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   154
37057
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   155
template <class E, MEMFLAGS F>
41176
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   156
E* MmapArrayAllocator<E, F>::allocate_or_null(size_t length) {
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   157
  size_t size = size_for(length);
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   158
  int alignment = os::vm_allocation_granularity();
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   159
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   160
  char* addr = os::reserve_memory(size, NULL, alignment, F);
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   161
  if (addr == NULL) {
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   162
    return NULL;
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   163
  }
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   164
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   165
  if (os::commit_memory(addr, size, !ExecMem, "Allocator (commit)")) {
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   166
    return (E*)addr;
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   167
  } else {
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   168
    os::release_memory(addr, size);
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   169
    return NULL;
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   170
  }
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   171
}
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   172
ff9f64534cff 8159422: Very high Concurrent Mark mark stack contention
tschatzl
parents: 40655
diff changeset
   173
template <class E, MEMFLAGS F>
37096
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   174
E* MmapArrayAllocator<E, F>::allocate(size_t length) {
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   175
  size_t size = size_for(length);
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   176
  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
   177
37057
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   178
  char* addr = os::reserve_memory(size, NULL, alignment, F);
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   179
  if (addr == NULL) {
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   180
    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
   181
  }
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   182
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   183
  os::commit_memory_or_exit(addr, size, !ExecMem, "Allocator (commit)");
37057
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   184
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   185
  return (E*)addr;
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   186
}
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   187
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   188
template <class E, MEMFLAGS F>
37096
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   189
void MmapArrayAllocator<E, F>::free(E* addr, size_t length) {
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   190
  bool result = os::release_memory((char*)addr, size_for(length));
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   191
  assert(result, "Failed to release memory");
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   192
}
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   193
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   194
template <class E, MEMFLAGS F>
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   195
size_t MallocArrayAllocator<E, F>::size_for(size_t length) {
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   196
  return length * sizeof(E);
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   197
}
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   198
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   199
template <class E, MEMFLAGS F>
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   200
E* MallocArrayAllocator<E, F>::allocate(size_t length) {
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   201
  return (E*)AllocateHeap(size_for(length), F);
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   202
}
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   203
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   204
template<class E, MEMFLAGS F>
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   205
void MallocArrayAllocator<E, F>::free(E* addr, size_t /*length*/) {
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   206
  FreeHeap(addr);
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   207
}
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   208
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   209
template <class E, MEMFLAGS F>
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   210
bool ArrayAllocator<E, F>::should_use_malloc(size_t length) {
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   211
  return MallocArrayAllocator<E, F>::size_for(length) < ArrayAllocatorMallocLimit;
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   212
}
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   213
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   214
template <class E, MEMFLAGS F>
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   215
E* ArrayAllocator<E, F>::allocate_malloc(size_t length) {
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   216
  return MallocArrayAllocator<E, F>::allocate(length);
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   217
}
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   218
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   219
template <class E, MEMFLAGS F>
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   220
E* ArrayAllocator<E, F>::allocate_mmap(size_t length) {
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   221
  return MmapArrayAllocator<E, F>::allocate(length);
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   222
}
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   223
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   224
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
   225
E* ArrayAllocator<E, F>::allocate(size_t length) {
37057
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   226
  if (should_use_malloc(length)) {
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   227
    return allocate_malloc(length);
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   228
  }
16682
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   229
37057
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   230
  return allocate_mmap(length);
16682
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   231
}
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   232
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   233
template <class E, MEMFLAGS F>
37057
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   234
E* ArrayAllocator<E, F>::reallocate(E* old_addr, size_t old_length, size_t new_length) {
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   235
  E* new_addr = (new_length > 0)
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   236
      ? allocate(new_length)
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   237
      : NULL;
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   238
37057
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   239
  if (new_addr != NULL && old_addr != NULL) {
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   240
    memcpy(new_addr, old_addr, MIN2(old_length, new_length) * sizeof(E));
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   241
  }
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   242
37057
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   243
  if (old_addr != NULL) {
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   244
    free(old_addr, old_length);
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   245
  }
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   246
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   247
  return new_addr;
23545
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   248
}
2c14fb03a06d 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
mgerdin
parents: 19696
diff changeset
   249
16682
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   250
template<class E, MEMFLAGS F>
37096
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   251
void ArrayAllocator<E, F>::free_malloc(E* addr, size_t length) {
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   252
  MallocArrayAllocator<E, F>::free(addr, length);
37057
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   253
}
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   254
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   255
template<class E, MEMFLAGS F>
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   256
void ArrayAllocator<E, F>::free_mmap(E* addr, size_t length) {
37096
42437cf54027 8151534: Refactor ArrayAllocator for easier reuse
stefank
parents: 37057
diff changeset
   257
  MmapArrayAllocator<E, F>::free(addr, length);
37057
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   258
}
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   259
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   260
template<class E, MEMFLAGS F>
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   261
void ArrayAllocator<E, F>::free(E* addr, size_t length) {
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   262
  if (addr != NULL) {
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   263
    if (should_use_malloc(length)) {
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   264
      free_malloc(addr, length);
16682
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   265
    } else {
37057
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 30293
diff changeset
   266
      free_mmap(addr, length);
16682
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   267
    }
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   268
  }
4e30a46f6b76 7197666: java -d64 -version core dumps in a box with lots of memory
brutisso
parents: 15855
diff changeset
   269
}
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 8325
diff changeset
   270
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   271
#endif // SHARE_VM_MEMORY_ALLOCATION_INLINE_HPP