Mercurial > hg > graal-jvmci-8
comparison src/share/vm/memory/allocation.cpp @ 10130:6f817ce50129
8010992: Remove calls to global ::operator new[] and new
Summary: disable use of global operator new and new[] which could cause unexpected exception and escape from NMT tracking.
Reviewed-by: coleenp, dholmes, zgu
Contributed-by: yumin.qi@oracle.com
author | minqi |
---|---|
date | Fri, 19 Apr 2013 11:08:52 -0700 |
parents | 59c790074993 |
children | 5a9fa2ba85f0 |
comparison
equal
deleted
inserted
replaced
10129:7815eaceaa8c | 10130:6f817ce50129 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2013, 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(); }; | |
54 void* _ValueObj::operator new(size_t size) { ShouldNotCallThis(); return 0; }; | 56 void* _ValueObj::operator new(size_t size) { ShouldNotCallThis(); return 0; }; |
55 void _ValueObj::operator delete(void* p) { ShouldNotCallThis(); }; | 57 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(); }; | |
56 | 60 |
57 void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data, | 61 void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data, |
58 size_t word_size, bool read_only, TRAPS) { | 62 size_t word_size, bool read_only, TRAPS) { |
59 // Klass has it's own operator new | 63 // Klass has it's own operator new |
60 return Metaspace::allocate(loader_data, word_size, read_only, | 64 return Metaspace::allocate(loader_data, word_size, read_only, |
78 } | 82 } |
79 | 83 |
80 void MetaspaceObj::print_address_on(outputStream* st) const { | 84 void MetaspaceObj::print_address_on(outputStream* st) const { |
81 st->print(" {"INTPTR_FORMAT"}", this); | 85 st->print(" {"INTPTR_FORMAT"}", this); |
82 } | 86 } |
83 | |
84 | 87 |
85 void* ResourceObj::operator new(size_t size, allocation_type type, MEMFLAGS flags) { | 88 void* ResourceObj::operator new(size_t size, allocation_type type, MEMFLAGS flags) { |
86 address res; | 89 address res; |
87 switch (type) { | 90 switch (type) { |
88 case C_HEAP: | 91 case C_HEAP: |
95 break; | 98 break; |
96 default: | 99 default: |
97 ShouldNotReachHere(); | 100 ShouldNotReachHere(); |
98 } | 101 } |
99 return res; | 102 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); | |
100 } | 107 } |
101 | 108 |
102 void* ResourceObj::operator new(size_t size, const std::nothrow_t& nothrow_constant, | 109 void* ResourceObj::operator new(size_t size, const std::nothrow_t& nothrow_constant, |
103 allocation_type type, MEMFLAGS flags) { | 110 allocation_type type, MEMFLAGS flags) { |
104 //should only call this with std::nothrow, use other operator new() otherwise | 111 //should only call this with std::nothrow, use other operator new() otherwise |
116 ShouldNotReachHere(); | 123 ShouldNotReachHere(); |
117 } | 124 } |
118 return res; | 125 return res; |
119 } | 126 } |
120 | 127 |
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 } | |
121 | 132 |
122 void ResourceObj::operator delete(void* p) { | 133 void ResourceObj::operator delete(void* p) { |
123 assert(((ResourceObj *)p)->allocated_on_C_heap(), | 134 assert(((ResourceObj *)p)->allocated_on_C_heap(), |
124 "delete only allowed for C_HEAP objects"); | 135 "delete only allowed for C_HEAP objects"); |
125 DEBUG_ONLY(((ResourceObj *)p)->_allocation_t[0] = (uintptr_t)badHeapOopVal;) | 136 DEBUG_ONLY(((ResourceObj *)p)->_allocation_t[0] = (uintptr_t)badHeapOopVal;) |
126 FreeHeap(p); | 137 FreeHeap(p); |
138 } | |
139 | |
140 void ResourceObj::operator delete [](void* p) { | |
141 operator delete(p); | |
127 } | 142 } |
128 | 143 |
129 #ifdef ASSERT | 144 #ifdef ASSERT |
130 void ResourceObj::set_allocation_type(address res, allocation_type type) { | 145 void ResourceObj::set_allocation_type(address res, allocation_type type) { |
131 // Set allocation type in the resource object | 146 // Set allocation type in the resource object |
358 // Chunk implementation | 373 // Chunk implementation |
359 | 374 |
360 void* Chunk::operator new(size_t requested_size, size_t length) { | 375 void* Chunk::operator new(size_t requested_size, size_t length) { |
361 // requested_size is equal to sizeof(Chunk) but in order for the arena | 376 // requested_size is equal to sizeof(Chunk) but in order for the arena |
362 // allocations to come out aligned as expected the size must be aligned | 377 // allocations to come out aligned as expected the size must be aligned |
363 // to expected arean alignment. | 378 // to expected arena alignment. |
364 // expect requested_size but if sizeof(Chunk) doesn't match isn't proper size we must align it. | 379 // expect requested_size but if sizeof(Chunk) doesn't match isn't proper size we must align it. |
365 assert(ARENA_ALIGN(requested_size) == aligned_overhead_size(), "Bad alignment"); | 380 assert(ARENA_ALIGN(requested_size) == aligned_overhead_size(), "Bad alignment"); |
366 size_t bytes = ARENA_ALIGN(requested_size) + length; | 381 size_t bytes = ARENA_ALIGN(requested_size) + length; |
367 switch (length) { | 382 switch (length) { |
368 case Chunk::size: return ChunkPool::large_pool()->allocate(bytes); | 383 case Chunk::size: return ChunkPool::large_pool()->allocate(bytes); |
667 #ifndef PRODUCT | 682 #ifndef PRODUCT |
668 // The global operator new should never be called since it will usually indicate | 683 // The global operator new should never be called since it will usually indicate |
669 // a memory leak. Use CHeapObj as the base class of such objects to make it explicit | 684 // a memory leak. Use CHeapObj as the base class of such objects to make it explicit |
670 // that they're allocated on the C heap. | 685 // that they're allocated on the C heap. |
671 // Commented out in product version to avoid conflicts with third-party C++ native code. | 686 // 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 | |
677 void* operator new(size_t size){ | 687 void* operator new(size_t size){ |
678 static bool warned = false; | 688 ShouldNotReachHere(); return 0; |
679 if (!warned && warn_new_operator) | 689 } |
680 warning("should not call global (default) operator new"); | 690 |
681 warned = true; | 691 void* operator new [](size_t size){ |
682 return (void *) AllocateHeap(size, "global operator new"); | 692 ShouldNotReachHere(); return 0; |
683 } | 693 } |
684 #endif | 694 |
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 } | |
685 | 702 |
686 void AllocatedObj::print() const { print_on(tty); } | 703 void AllocatedObj::print() const { print_on(tty); } |
687 void AllocatedObj::print_value() const { print_value_on(tty); } | 704 void AllocatedObj::print_value() const { print_value_on(tty); } |
688 | 705 |
689 void AllocatedObj::print_on(outputStream* st) const { | 706 void AllocatedObj::print_on(outputStream* st) const { |