< prev index next >

src/hotspot/share/gc/z/zNMethodData.cpp


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/growableArray.hpp"
32 
33 size_t ZNMethodDataOops::header_size() {
34   const size_t size = sizeof(ZNMethodDataOops);
35   assert(is_aligned(size, sizeof(oop*)), "Header misaligned");
36   return size;
37 }
38 
39 ZNMethodDataOops* ZNMethodDataOops::create(const GrowableArray<oop*>& immediates, bool has_non_immediates) {
40   // Allocate memory for the ZNMethodDataOops object
41   // plus the immediate oop* array that follows right after.
42   const size_t size = ZNMethodDataOops::header_size() + (sizeof(oop*) * immediates.length());
43   void* const mem = NEW_C_HEAP_ARRAY(uint8_t, size, mtGC);
44   return ::new (mem) ZNMethodDataOops(immediates, has_non_immediates);
45 }
46 
47 void ZNMethodDataOops::destroy(ZNMethodDataOops* oops) {
48   FREE_C_HEAP_ARRAY(uint8_t, oops);
49 }
50 
51 ZNMethodDataOops::ZNMethodDataOops(const GrowableArray<oop*>& immediates, bool has_non_immediates) :
52     _nimmediates(immediates.length()),
53     _has_non_immediates(has_non_immediates) {
54   // Save all immediate oops
55   for (size_t i = 0; i < _nimmediates; i++) {
56     immediates_begin()[i] = immediates.at(i);
57   }
58 }
59 
60 size_t ZNMethodDataOops::immediates_count() const {
61   return _nimmediates;
62 }
63 
64 oop** ZNMethodDataOops::immediates_begin() const {
65   // The immediate oop* array starts immediately after this object
66   return (oop**)((uintptr_t)this + header_size());
67 }
68 
69 oop** ZNMethodDataOops::immediates_end() const {
70   return immediates_begin() + immediates_count();
71 }
72 
73 bool ZNMethodDataOops::has_non_immediates() const {
74   return _has_non_immediates;
75 }
76 
77 ZNMethodData::ZNMethodData() :
78     _lock(),
79     _oops(NULL) {}
80 
81 ZNMethodData::~ZNMethodData() {
82   ZNMethodDataOops::destroy(_oops);
83 }
84 
85 ZReentrantLock* ZNMethodData::lock() {
86   return &_lock;
87 }
88 
89 ZNMethodDataOops* ZNMethodData::oops() const {
90   return OrderAccess::load_acquire(&_oops);
91 }
92 
93 ZNMethodDataOops* ZNMethodData::swap_oops(ZNMethodDataOops* new_oops) {
94   ZLocker<ZReentrantLock> locker(&_lock);
95   ZNMethodDataOops* const old_oops = _oops;
96   _oops = new_oops;
97   return old_oops;
98 }
< prev index next >