src/share/vm/memory/allocation.cpp

changeset 4967
5a9fa2ba85f0
parent 4962
6f817ce50129
child 4993
746b070f5022
child 5246
4b52137b07c9
equal deleted inserted replaced
4962:6f817ce50129 4967:5a9fa2ba85f0
1 /* 1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
49 # include "os_bsd.inline.hpp" 49 # include "os_bsd.inline.hpp"
50 #endif 50 #endif
51 51
52 void* StackObj::operator new(size_t size) { ShouldNotCallThis(); return 0; }; 52 void* StackObj::operator new(size_t size) { ShouldNotCallThis(); return 0; };
53 void StackObj::operator delete(void* p) { ShouldNotCallThis(); }; 53 void StackObj::operator delete(void* p) { ShouldNotCallThis(); };
54 void* StackObj::operator new [](size_t size) { ShouldNotCallThis(); return 0; };
55 void StackObj::operator delete [](void* p) { ShouldNotCallThis(); };
56 void* _ValueObj::operator new(size_t size) { ShouldNotCallThis(); return 0; }; 54 void* _ValueObj::operator new(size_t size) { ShouldNotCallThis(); return 0; };
57 void _ValueObj::operator delete(void* p) { ShouldNotCallThis(); }; 55 void _ValueObj::operator delete(void* p) { ShouldNotCallThis(); };
58 void* _ValueObj::operator new [](size_t size) { ShouldNotCallThis(); return 0; };
59 void _ValueObj::operator delete [](void* p) { ShouldNotCallThis(); };
60 56
61 void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data, 57 void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data,
62 size_t word_size, bool read_only, TRAPS) { 58 size_t word_size, bool read_only, TRAPS) {
63 // Klass has it's own operator new 59 // Klass has it's own operator new
64 return Metaspace::allocate(loader_data, word_size, read_only, 60 return Metaspace::allocate(loader_data, word_size, read_only,
82 } 78 }
83 79
84 void MetaspaceObj::print_address_on(outputStream* st) const { 80 void MetaspaceObj::print_address_on(outputStream* st) const {
85 st->print(" {"INTPTR_FORMAT"}", this); 81 st->print(" {"INTPTR_FORMAT"}", this);
86 } 82 }
83
87 84
88 void* ResourceObj::operator new(size_t size, allocation_type type, MEMFLAGS flags) { 85 void* ResourceObj::operator new(size_t size, allocation_type type, MEMFLAGS flags) {
89 address res; 86 address res;
90 switch (type) { 87 switch (type) {
91 case C_HEAP: 88 case C_HEAP:
98 break; 95 break;
99 default: 96 default:
100 ShouldNotReachHere(); 97 ShouldNotReachHere();
101 } 98 }
102 return res; 99 return res;
103 }
104
105 void* ResourceObj::operator new [](size_t size, allocation_type type, MEMFLAGS flags) {
106 return (address) operator new(size, type, flags);
107 } 100 }
108 101
109 void* ResourceObj::operator new(size_t size, const std::nothrow_t& nothrow_constant, 102 void* ResourceObj::operator new(size_t size, const std::nothrow_t& nothrow_constant,
110 allocation_type type, MEMFLAGS flags) { 103 allocation_type type, MEMFLAGS flags) {
111 //should only call this with std::nothrow, use other operator new() otherwise 104 //should only call this with std::nothrow, use other operator new() otherwise
123 ShouldNotReachHere(); 116 ShouldNotReachHere();
124 } 117 }
125 return res; 118 return res;
126 } 119 }
127 120
128 void* ResourceObj::operator new [](size_t size, const std::nothrow_t& nothrow_constant,
129 allocation_type type, MEMFLAGS flags) {
130 return (address)operator new(size, nothrow_constant, type, flags);
131 }
132 121
133 void ResourceObj::operator delete(void* p) { 122 void ResourceObj::operator delete(void* p) {
134 assert(((ResourceObj *)p)->allocated_on_C_heap(), 123 assert(((ResourceObj *)p)->allocated_on_C_heap(),
135 "delete only allowed for C_HEAP objects"); 124 "delete only allowed for C_HEAP objects");
136 DEBUG_ONLY(((ResourceObj *)p)->_allocation_t[0] = (uintptr_t)badHeapOopVal;) 125 DEBUG_ONLY(((ResourceObj *)p)->_allocation_t[0] = (uintptr_t)badHeapOopVal;)
137 FreeHeap(p); 126 FreeHeap(p);
138 }
139
140 void ResourceObj::operator delete [](void* p) {
141 operator delete(p);
142 } 127 }
143 128
144 #ifdef ASSERT 129 #ifdef ASSERT
145 void ResourceObj::set_allocation_type(address res, allocation_type type) { 130 void ResourceObj::set_allocation_type(address res, allocation_type type) {
146 // Set allocation type in the resource object 131 // Set allocation type in the resource object
373 // Chunk implementation 358 // Chunk implementation
374 359
375 void* Chunk::operator new(size_t requested_size, size_t length) { 360 void* Chunk::operator new(size_t requested_size, size_t length) {
376 // requested_size is equal to sizeof(Chunk) but in order for the arena 361 // requested_size is equal to sizeof(Chunk) but in order for the arena
377 // allocations to come out aligned as expected the size must be aligned 362 // allocations to come out aligned as expected the size must be aligned
378 // to expected arena alignment. 363 // to expected arean alignment.
379 // expect requested_size but if sizeof(Chunk) doesn't match isn't proper size we must align it. 364 // expect requested_size but if sizeof(Chunk) doesn't match isn't proper size we must align it.
380 assert(ARENA_ALIGN(requested_size) == aligned_overhead_size(), "Bad alignment"); 365 assert(ARENA_ALIGN(requested_size) == aligned_overhead_size(), "Bad alignment");
381 size_t bytes = ARENA_ALIGN(requested_size) + length; 366 size_t bytes = ARENA_ALIGN(requested_size) + length;
382 switch (length) { 367 switch (length) {
383 case Chunk::size: return ChunkPool::large_pool()->allocate(bytes); 368 case Chunk::size: return ChunkPool::large_pool()->allocate(bytes);
682 #ifndef PRODUCT 667 #ifndef PRODUCT
683 // The global operator new should never be called since it will usually indicate 668 // The global operator new should never be called since it will usually indicate
684 // a memory leak. Use CHeapObj as the base class of such objects to make it explicit 669 // a memory leak. Use CHeapObj as the base class of such objects to make it explicit
685 // that they're allocated on the C heap. 670 // that they're allocated on the C heap.
686 // Commented out in product version to avoid conflicts with third-party C++ native code. 671 // Commented out in product version to avoid conflicts with third-party C++ native code.
672 // %% note this is causing a problem on solaris debug build. the global
673 // new is being called from jdk source and causing data corruption.
674 // src/share/native/sun/awt/font/fontmanager/textcache/hsMemory.cpp::hsSoftNew
675 // define CATCH_OPERATOR_NEW_USAGE if you want to use this.
676 #ifdef CATCH_OPERATOR_NEW_USAGE
687 void* operator new(size_t size){ 677 void* operator new(size_t size){
688 ShouldNotReachHere(); return 0; 678 static bool warned = false;
689 } 679 if (!warned && warn_new_operator)
690 680 warning("should not call global (default) operator new");
691 void* operator new [](size_t size){ 681 warned = true;
692 ShouldNotReachHere(); return 0; 682 return (void *) AllocateHeap(size, "global operator new");
693 } 683 }
694 684 #endif
695 void* operator new(size_t size, const std::nothrow_t& nothrow_constant){
696 ShouldNotReachHere(); return 0;
697 }
698
699 void* operator new [](size_t size, std::nothrow_t& nothrow_constant){
700 ShouldNotReachHere(); return 0;
701 }
702 685
703 void AllocatedObj::print() const { print_on(tty); } 686 void AllocatedObj::print() const { print_on(tty); }
704 void AllocatedObj::print_value() const { print_value_on(tty); } 687 void AllocatedObj::print_value() const { print_value_on(tty); }
705 688
706 void AllocatedObj::print_on(outputStream* st) const { 689 void AllocatedObj::print_on(outputStream* st) const {

mercurial