hotspot/src/share/vm/memory/allocation.cpp
author hseigel
Wed, 16 Aug 2017 11:17:54 -0400
changeset 46818 d0475215ae39
parent 46746 ea379ebb9447
permissions -rw-r--r--
8186089: Move Arena to its own header file Summary: Move classes Chunk and Arena to new arena.hpp and arena.cpp files Reviewed-by: coleenp, gtriantafill
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 40655
diff changeset
     2
 * Copyright (c) 1997, 2017, 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: 6415
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29580
diff changeset
    26
#include "gc/shared/genCollectedHeap.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6415
diff changeset
    27
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6415
diff changeset
    28
#include "memory/allocation.inline.hpp"
46818
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents: 46746
diff changeset
    29
#include "memory/arena.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    30
#include "memory/metaspaceShared.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6415
diff changeset
    31
#include "memory/resourceArea.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    32
#include "memory/universe.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 38254
diff changeset
    33
#include "runtime/atomic.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6415
diff changeset
    34
#include "runtime/os.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6415
diff changeset
    35
#include "runtime/task.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6415
diff changeset
    36
#include "runtime/threadCritical.hpp"
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 10565
diff changeset
    37
#include "services/memTracker.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6415
diff changeset
    38
#include "utilities/ostream.hpp"
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 10565
diff changeset
    39
19696
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18686
diff changeset
    40
void* StackObj::operator new(size_t size)     throw() { ShouldNotCallThis(); return 0; }
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18686
diff changeset
    41
void  StackObj::operator delete(void* p)              { ShouldNotCallThis(); }
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18686
diff changeset
    42
void* StackObj::operator new [](size_t size)  throw() { ShouldNotCallThis(); return 0; }
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18686
diff changeset
    43
void  StackObj::operator delete [](void* p)           { ShouldNotCallThis(); }
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17087
diff changeset
    44
19696
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18686
diff changeset
    45
void* _ValueObj::operator new(size_t size)    throw() { ShouldNotCallThis(); return 0; }
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18686
diff changeset
    46
void  _ValueObj::operator delete(void* p)             { ShouldNotCallThis(); }
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18686
diff changeset
    47
void* _ValueObj::operator new [](size_t size) throw() { ShouldNotCallThis(); return 0; }
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18686
diff changeset
    48
void  _ValueObj::operator delete [](void* p)          { ShouldNotCallThis(); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    50
void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data,
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 40655
diff changeset
    51
                                 size_t word_size,
19696
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18686
diff changeset
    52
                                 MetaspaceObj::Type type, TRAPS) throw() {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    53
  // Klass has it's own operator new
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 40655
diff changeset
    54
  return Metaspace::allocate(loader_data, word_size, type, THREAD);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    55
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    56
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    57
bool MetaspaceObj::is_shared() const {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    58
  return MetaspaceShared::is_in_shared_space(this);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    59
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    60
14579
7f6ce6e3dd80 8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
coleenp
parents: 14120
diff changeset
    61
bool MetaspaceObj::is_metaspace_object() const {
24457
0e20b36df5c4 8038212: Method::is_valid_method() check has performance regression impact for stackwalking
coleenp
parents: 24431
diff changeset
    62
  return Metaspace::contains((void*)this);
14579
7f6ce6e3dd80 8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
coleenp
parents: 14120
diff changeset
    63
}
7f6ce6e3dd80 8003635: NPG: AsynchGetCallTrace broken by Method* virtual call
coleenp
parents: 14120
diff changeset
    64
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    65
void MetaspaceObj::print_address_on(outputStream* st) const {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23446
diff changeset
    66
  st->print(" {" INTPTR_FORMAT "}", p2i(this));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    67
}
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
    68
46818
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents: 46746
diff changeset
    69
void* ResourceObj::operator new(size_t size, Arena *arena) throw() {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents: 46746
diff changeset
    70
  address res = (address)arena->Amalloc(size);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents: 46746
diff changeset
    71
  DEBUG_ONLY(set_allocation_type(res, ARENA);)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents: 46746
diff changeset
    72
  return res;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents: 46746
diff changeset
    73
}
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents: 46746
diff changeset
    74
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents: 46746
diff changeset
    75
void* ResourceObj::operator new [](size_t size, Arena *arena) throw() {
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents: 46746
diff changeset
    76
  address res = (address)arena->Amalloc(size);
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents: 46746
diff changeset
    77
  DEBUG_ONLY(set_allocation_type(res, ARENA);)
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents: 46746
diff changeset
    78
  return res;
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents: 46746
diff changeset
    79
}
d0475215ae39 8186089: Move Arena to its own header file
hseigel
parents: 46746
diff changeset
    80
19696
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18686
diff changeset
    81
void* ResourceObj::operator new(size_t size, allocation_type type, MEMFLAGS flags) throw() {
33589
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 33105
diff changeset
    82
  address res = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
   case C_HEAP:
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 10565
diff changeset
    85
    res = (address)AllocateHeap(size, flags, CALLER_PC);
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
    86
    DEBUG_ONLY(set_allocation_type(res, C_HEAP);)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
   case RESOURCE_AREA:
6183
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 6180
diff changeset
    89
    // new(size) sets allocation type RESOURCE_AREA.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    res = (address)operator new(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
   default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  return res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
19696
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18686
diff changeset
    98
void* ResourceObj::operator new [](size_t size, allocation_type type, MEMFLAGS flags) throw() {
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17087
diff changeset
    99
  return (address) operator new(size, type, flags);
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17087
diff changeset
   100
}
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17087
diff changeset
   101
14083
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   102
void* ResourceObj::operator new(size_t size, const std::nothrow_t&  nothrow_constant,
19696
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18686
diff changeset
   103
    allocation_type type, MEMFLAGS flags) throw() {
33589
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 33105
diff changeset
   104
  // should only call this with std::nothrow, use other operator new() otherwise
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 33105
diff changeset
   105
  address res = NULL;
14083
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   106
  switch (type) {
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   107
   case C_HEAP:
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   108
    res = (address)AllocateHeap(size, flags, CALLER_PC, AllocFailStrategy::RETURN_NULL);
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   109
    DEBUG_ONLY(if (res!= NULL) set_allocation_type(res, C_HEAP);)
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   110
    break;
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   111
   case RESOURCE_AREA:
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   112
    // new(size) sets allocation type RESOURCE_AREA.
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   113
    res = (address)operator new(size, std::nothrow);
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   114
    break;
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   115
   default:
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   116
    ShouldNotReachHere();
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   117
  }
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   118
  return res;
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   119
}
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   120
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17087
diff changeset
   121
void* ResourceObj::operator new [](size_t size, const std::nothrow_t&  nothrow_constant,
19696
bd5a0131bde1 8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents: 18686
diff changeset
   122
    allocation_type type, MEMFLAGS flags) throw() {
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17087
diff changeset
   123
  return (address)operator new(size, nothrow_constant, type, flags);
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17087
diff changeset
   124
}
14083
103054a71a30 8000617: It should be possible to allocate memory without the VM dying.
nloodin
parents: 13728
diff changeset
   125
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
void ResourceObj::operator delete(void* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  assert(((ResourceObj *)p)->allocated_on_C_heap(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
         "delete only allowed for C_HEAP objects");
7440
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   129
  DEBUG_ONLY(((ResourceObj *)p)->_allocation_t[0] = (uintptr_t)badHeapOopVal;)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  FreeHeap(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
17376
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17087
diff changeset
   133
void ResourceObj::operator delete [](void* p) {
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17087
diff changeset
   134
  operator delete(p);
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17087
diff changeset
   135
}
4ee999c3c007 8012902: remove use of global operator new - take 2
minqi
parents: 17087
diff changeset
   136
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   137
#ifdef ASSERT
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   138
void ResourceObj::set_allocation_type(address res, allocation_type type) {
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   139
    // Set allocation type in the resource object
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   140
    uintptr_t allocation = (uintptr_t)res;
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31592
diff changeset
   141
    assert((allocation & allocation_mask) == 0, "address should be aligned to 4 bytes at least: " INTPTR_FORMAT, p2i(res));
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   142
    assert(type <= allocation_mask, "incorrect allocation type");
7440
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   143
    ResourceObj* resobj = (ResourceObj *)res;
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   144
    resobj->_allocation_t[0] = ~(allocation + type);
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   145
    if (type != STACK_OR_EMBEDDED) {
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   146
      // Called from operator new() and CollectionSetChooser(),
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   147
      // set verification value.
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   148
      resobj->_allocation_t[1] = (uintptr_t)&(resobj->_allocation_t[1]) + type;
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   149
    }
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   150
}
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   151
6183
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 6180
diff changeset
   152
ResourceObj::allocation_type ResourceObj::get_allocation_type() const {
7440
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   153
    assert(~(_allocation_t[0] | allocation_mask) == (uintptr_t)this, "lost resource object");
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   154
    return (allocation_type)((~_allocation_t[0]) & allocation_mask);
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   155
}
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   156
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   157
bool ResourceObj::is_type_set() const {
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   158
    allocation_type type = (allocation_type)(_allocation_t[1] & allocation_mask);
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   159
    return get_allocation_type()  == type &&
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   160
           (_allocation_t[1] - type) == (uintptr_t)(&_allocation_t[1]);
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   161
}
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   162
6183
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 6180
diff changeset
   163
ResourceObj::ResourceObj() { // default constructor
7440
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   164
    if (~(_allocation_t[0] | allocation_mask) != (uintptr_t)this) {
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   165
      // Operator new() is not called for allocations
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   166
      // on stack and for embedded objects.
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   167
      set_allocation_type((address)this, STACK_OR_EMBEDDED);
7440
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   168
    } else if (allocated_on_stack()) { // STACK_OR_EMBEDDED
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   169
      // For some reason we got a value which resembles
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   170
      // an embedded or stack object (operator new() does not
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   171
      // set such type). Keep it since it is valid value
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   172
      // (even if it was garbage).
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   173
      // Ignore garbage in other fields.
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   174
    } else if (is_type_set()) {
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   175
      // Operator new() was called and type was set.
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   176
      assert(!allocated_on_stack(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31592
diff changeset
   177
             "not embedded or stack, this(" PTR_FORMAT ") type %d a[0]=(" PTR_FORMAT ") a[1]=(" PTR_FORMAT ")",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31592
diff changeset
   178
             p2i(this), get_allocation_type(), _allocation_t[0], _allocation_t[1]);
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   179
    } else {
7440
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   180
      // Operator new() was not called.
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   181
      // Assume that it is embedded or stack object.
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   182
      set_allocation_type((address)this, STACK_OR_EMBEDDED);
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   183
    }
7440
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   184
    _allocation_t[1] = 0; // Zap verification value
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   185
}
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   186
6183
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 6180
diff changeset
   187
ResourceObj::ResourceObj(const ResourceObj& r) { // default copy constructor
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   188
    // Used in ClassFileParser::parse_constant_pool_entries() for ClassFileStream.
7440
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   189
    // Note: garbage may resembles valid value.
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   190
    assert(~(_allocation_t[0] | allocation_mask) != (uintptr_t)this || !is_type_set(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31592
diff changeset
   191
           "embedded or stack only, this(" PTR_FORMAT ") type %d a[0]=(" PTR_FORMAT ") a[1]=(" PTR_FORMAT ")",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31592
diff changeset
   192
           p2i(this), get_allocation_type(), _allocation_t[0], _allocation_t[1]);
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   193
    set_allocation_type((address)this, STACK_OR_EMBEDDED);
7440
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   194
    _allocation_t[1] = 0; // Zap verification value
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   195
}
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   196
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   197
ResourceObj& ResourceObj::operator=(const ResourceObj& r) { // default copy assignment
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   198
    // Used in InlineTree::ok_to_inline() for WarmCallInfo.
7440
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   199
    assert(allocated_on_stack(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31592
diff changeset
   200
           "copy only into local, this(" PTR_FORMAT ") type %d a[0]=(" PTR_FORMAT ") a[1]=(" PTR_FORMAT ")",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31592
diff changeset
   201
           p2i(this), get_allocation_type(), _allocation_t[0], _allocation_t[1]);
7440
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   202
    // Keep current _allocation_t value;
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   203
    return *this;
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   204
}
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   205
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   206
ResourceObj::~ResourceObj() {
6183
4c74cfe14f20 6975078: assert(allocated_on_res_area() || allocated_on_C_heap() || allocated_on_arena()
kvn
parents: 6180
diff changeset
   207
    // allocated_on_C_heap() also checks that encoded (in _allocation) address == this.
7440
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   208
    if (!allocated_on_C_heap()) { // ResourceObj::delete() will zap _allocation for C_heap.
eabaf35910a1 6993125: runThese crashes with assert(Thread::current()->on_local_stack((address)this))
kvn
parents: 7397
diff changeset
   209
      _allocation_t[0] = (uintptr_t)badHeapOopVal; // zap type
6180
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   210
    }
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   211
}
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   212
#endif // ASSERT
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   213
53c1bf468c81 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 5547
diff changeset
   214
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
void trace_heap_malloc(size_t size, const char* name, void* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  // A lock is not needed here - tty uses a lock internally
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23446
diff changeset
   217
  tty->print_cr("Heap malloc " INTPTR_FORMAT " " SIZE_FORMAT " %s", p2i(p), size, name == NULL ? "" : name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
void trace_heap_free(void* p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  // A lock is not needed here - tty uses a lock internally
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23446
diff changeset
   223
  tty->print_cr("Heap free   " INTPTR_FORMAT, p2i(p));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
//--------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
// Non-product code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
void AllocatedObj::print() const       { print_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
void AllocatedObj::print_value() const { print_value_on(tty); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
void AllocatedObj::print_on(outputStream* st) const {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23446
diff changeset
   234
  st->print_cr("AllocatedObj(" INTPTR_FORMAT ")", p2i(this));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
void AllocatedObj::print_value_on(outputStream* st) const {
24424
2658d7834c6e 8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents: 23446
diff changeset
   238
  st->print("AllocatedObj(" INTPTR_FORMAT ")", p2i(this));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
AllocStats::AllocStats() {
8320
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7440
diff changeset
   242
  start_mallocs      = os::num_mallocs;
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7440
diff changeset
   243
  start_frees        = os::num_frees;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  start_malloc_bytes = os::alloc_bytes;
8320
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7440
diff changeset
   245
  start_mfree_bytes  = os::free_bytes;
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7440
diff changeset
   246
  start_res_bytes    = Arena::_bytes_allocated;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
8320
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7440
diff changeset
   249
julong  AllocStats::num_mallocs() { return os::num_mallocs - start_mallocs; }
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7440
diff changeset
   250
julong  AllocStats::alloc_bytes() { return os::alloc_bytes - start_malloc_bytes; }
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7440
diff changeset
   251
julong  AllocStats::num_frees()   { return os::num_frees - start_frees; }
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7440
diff changeset
   252
julong  AllocStats::free_bytes()  { return os::free_bytes - start_mfree_bytes; }
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7440
diff changeset
   253
julong  AllocStats::resource_bytes() { return Arena::_bytes_allocated - start_res_bytes; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
void    AllocStats::print() {
8320
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7440
diff changeset
   255
  tty->print_cr(UINT64_FORMAT " mallocs (" UINT64_FORMAT "MB), "
31592
43f48e165466 8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents: 30764
diff changeset
   256
                UINT64_FORMAT " frees (" UINT64_FORMAT "MB), " UINT64_FORMAT "MB resrc",
8320
544210b4dd48 7017124: Fix some VM stats to avoid 32-bit overflow
kvn
parents: 7440
diff changeset
   257
                num_mallocs(), alloc_bytes()/M, num_frees(), free_bytes()/M, resource_bytes()/M);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
ReallocMark::ReallocMark() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
#ifdef ASSERT
34633
2a6c7c7b30a7 8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents: 33589
diff changeset
   262
  Thread *thread = Thread::current();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  _nesting = thread->resource_area()->nesting();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
void ReallocMark::check() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  if (_nesting != Thread::current()->resource_area()->nesting()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
    fatal("allocation bug: array could grow within nested ResourceMark");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
#endif // Non-product