1 /*
2 * Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
68 os::free(p);
69 }
70
71 void* MetaspaceObj::_shared_metaspace_base = nullptr;
72 void* MetaspaceObj::_shared_metaspace_top = nullptr;
73
74 void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data,
75 size_t word_size,
76 MetaspaceObj::Type type, TRAPS) throw() {
77 // Klass has its own operator new
78 return Metaspace::allocate(loader_data, word_size, type, THREAD);
79 }
80
81 void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data,
82 size_t word_size,
83 MetaspaceObj::Type type) throw() {
84 assert(!Thread::current()->is_Java_thread(), "only allowed by non-Java thread");
85 return Metaspace::allocate(loader_data, word_size, type);
86 }
87
88 bool MetaspaceObj::is_valid(const MetaspaceObj* p) {
89 // Weed out obvious bogus values first without traversing metaspace
90 if ((size_t)p < os::min_page_size()) {
91 return false;
92 } else if (!is_aligned((address)p, sizeof(MetaWord))) {
93 return false;
94 }
95 return Metaspace::contains((void*)p);
96 }
97
98 void MetaspaceObj::print_address_on(outputStream* st) const {
99 st->print(" {" PTR_FORMAT "}", p2i(this));
100 }
101
102 //
103 // ArenaObj
104 //
105
106 void* ArenaObj::operator new(size_t size, Arena *arena) throw() {
107 return arena->Amalloc(size);
|
1 /*
2 * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
68 os::free(p);
69 }
70
71 void* MetaspaceObj::_shared_metaspace_base = nullptr;
72 void* MetaspaceObj::_shared_metaspace_top = nullptr;
73
74 void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data,
75 size_t word_size,
76 MetaspaceObj::Type type, TRAPS) throw() {
77 // Klass has its own operator new
78 return Metaspace::allocate(loader_data, word_size, type, THREAD);
79 }
80
81 void* MetaspaceObj::operator new(size_t size, ClassLoaderData* loader_data,
82 size_t word_size,
83 MetaspaceObj::Type type) throw() {
84 assert(!Thread::current()->is_Java_thread(), "only allowed by non-Java thread");
85 return Metaspace::allocate(loader_data, word_size, type);
86 }
87
88
89 // Work-around -- see JDK-8331086
90 void* MetaspaceObj::operator new(size_t size, MEMFLAGS flags) throw() {
91 void* p = AllocateHeap(size, flags, CALLER_PC);
92 memset(p, 0, size);
93 return p;
94 }
95
96 bool MetaspaceObj::is_valid(const MetaspaceObj* p) {
97 // Weed out obvious bogus values first without traversing metaspace
98 if ((size_t)p < os::min_page_size()) {
99 return false;
100 } else if (!is_aligned((address)p, sizeof(MetaWord))) {
101 return false;
102 }
103 return Metaspace::contains((void*)p);
104 }
105
106 void MetaspaceObj::print_address_on(outputStream* st) const {
107 st->print(" {" PTR_FORMAT "}", p2i(this));
108 }
109
110 //
111 // ArenaObj
112 //
113
114 void* ArenaObj::operator new(size_t size, Arena *arena) throw() {
115 return arena->Amalloc(size);
|