5 * under the terms of the GNU General Public License version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This code is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 */
22
23 #include "precompiled.hpp"
24 #include "gc/z/zLock.inline.hpp"
25 #include "gc/z/zNMethodAllocator.hpp"
26 #include "gc/z/zNMethodData.hpp"
27 #include "memory/allocation.hpp"
28 #include "runtime/atomic.hpp"
29 #include "runtime/orderAccess.hpp"
30 #include "utilities/align.hpp"
31 #include "utilities/debug.hpp"
32 #include "utilities/growableArray.hpp"
33
34 size_t ZNMethodDataOops::header_size() {
35 const size_t size = sizeof(ZNMethodDataOops);
36 assert(is_aligned(size, sizeof(oop*)), "Header misaligned");
37 return size;
38 }
39
40 ZNMethodDataOops* ZNMethodDataOops::create(const GrowableArray<oop*>& immediates, bool has_non_immediates) {
41 // Allocate memory for the ZNMethodDataOops object
42 // plus the immediate oop* array that follows right after.
43 const size_t size = ZNMethodDataOops::header_size() + (sizeof(oop*) * immediates.length());
44 void* const mem = ZNMethodAllocator::allocate(size);
45 return ::new (mem) ZNMethodDataOops(immediates, has_non_immediates);
46 }
47
48 void ZNMethodDataOops::destroy(ZNMethodDataOops* oops) {
49 ZNMethodAllocator::free(oops);
50 }
51
52 ZNMethodDataOops::ZNMethodDataOops(const GrowableArray<oop*>& immediates, bool has_non_immediates) :
53 _nimmediates(immediates.length()),
54 _has_non_immediates(has_non_immediates) {
55 // Save all immediate oops
56 for (size_t i = 0; i < _nimmediates; i++) {
57 immediates_begin()[i] = immediates.at(i);
58 }
59 }
60
61 size_t ZNMethodDataOops::immediates_count() const {
62 return _nimmediates;
63 }
64
65 oop** ZNMethodDataOops::immediates_begin() const {
66 // The immediate oop* array starts immediately after this object
67 return (oop**)((uintptr_t)this + header_size());
68 }
69
70 oop** ZNMethodDataOops::immediates_end() const {
71 return immediates_begin() + immediates_count();
72 }
73
74 bool ZNMethodDataOops::has_non_immediates() const {
75 return _has_non_immediates;
76 }
77
78 ZNMethodData::ZNMethodData() :
79 _lock(),
80 _oops(NULL) {}
81
82 ZNMethodData::~ZNMethodData() {
83 ZNMethodAllocator::free(_oops);
84 }
85
86 ZReentrantLock* ZNMethodData::lock() {
87 return &_lock;
88 }
89
90 ZNMethodDataOops* ZNMethodData::oops() const {
91 return OrderAccess::load_acquire(&_oops);
92 }
93
94 ZNMethodDataOops* ZNMethodData::swap_oops(ZNMethodDataOops* new_oops) {
95 return Atomic::xchg(new_oops, &_oops);
96 }
|
5 * under the terms of the GNU General Public License version 2 only, as
6 * published by the Free Software Foundation.
7 *
8 * This code is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * version 2 for more details (a copy is included in the LICENSE file that
12 * accompanied this code).
13 *
14 * You should have received a copy of the GNU General Public License version
15 * 2 along with this work; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19 * or visit www.oracle.com if you need additional information or have any
20 * questions.
21 */
22
23 #include "precompiled.hpp"
24 #include "gc/z/zLock.inline.hpp"
25 #include "gc/z/zNMethodData.hpp"
26 #include "memory/allocation.hpp"
27 #include "runtime/atomic.hpp"
28 #include "runtime/orderAccess.hpp"
29 #include "utilities/align.hpp"
30 #include "utilities/debug.hpp"
31 #include "utilities/globalCounter.inline.hpp"
32 #include "utilities/growableArray.hpp"
33
34 size_t ZNMethodDataOops::header_size() {
35 const size_t size = sizeof(ZNMethodDataOops);
36 assert(is_aligned(size, sizeof(oop*)), "Header misaligned");
37 return size;
38 }
39
40 ZNMethodDataOops* ZNMethodDataOops::create(const GrowableArray<oop*>& immediates, bool has_non_immediates) {
41 // Allocate memory for the ZNMethodDataOops object
42 // plus the immediate oop* array that follows right after.
43 const size_t size = ZNMethodDataOops::header_size() + (sizeof(oop*) * immediates.length());
44 void* const mem = NEW_C_HEAP_ARRAY(uint8_t, size, mtGC);
45 return ::new (mem) ZNMethodDataOops(immediates, has_non_immediates);
46 }
47
48 void ZNMethodDataOops::destroy(ZNMethodDataOops* oops) {
49 FREE_C_HEAP_ARRAY(uint8_t, oops);
50 }
51
52 ZNMethodDataOops::ZNMethodDataOops(const GrowableArray<oop*>& immediates, bool has_non_immediates) :
53 _nimmediates(immediates.length()),
54 _has_non_immediates(has_non_immediates) {
55 // Save all immediate oops
56 for (size_t i = 0; i < _nimmediates; i++) {
57 immediates_begin()[i] = immediates.at(i);
58 }
59 }
60
61 size_t ZNMethodDataOops::immediates_count() const {
62 return _nimmediates;
63 }
64
65 oop** ZNMethodDataOops::immediates_begin() const {
66 // The immediate oop* array starts immediately after this object
67 return (oop**)((uintptr_t)this + header_size());
68 }
69
70 oop** ZNMethodDataOops::immediates_end() const {
71 return immediates_begin() + immediates_count();
72 }
73
74 bool ZNMethodDataOops::has_non_immediates() const {
75 return _has_non_immediates;
76 }
77
78 ZNMethodData::ZNMethodData() :
79 _lock(),
80 _oops(NULL) {}
81
82 ZNMethodData::~ZNMethodData() {
83 ZNMethodDataOops::destroy(_oops);
84 }
85
86 ZReentrantLock* ZNMethodData::lock() {
87 return &_lock;
88 }
89
90 ZNMethodDataOops* ZNMethodData::oops() const {
91 return OrderAccess::load_acquire(&_oops);
92 }
93
94 ZNMethodDataOops* ZNMethodData::swap_oops(ZNMethodDataOops* new_oops) {
95 ZNMethodDataOops* const oops = Atomic::xchg(new_oops, &_oops);
96 if (oops != NULL) {
97 GlobalCounter::write_synchronize();
98 }
99 return oops;
100 }
|