< prev index next >

src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp

8221260: Initialize more class members on construction, remove some unused ones
Reviewed-by:

0 /*                                                                                                                         
1  * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.                                            
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.                                                           
3  *                                                                                                                         
4  * This code is free software; you can redistribute it and/or modify it                                                    
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.                                                                                                              

0 /*
1  * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3  *
4  * This code is free software; you can redistribute it and/or modify it
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.

187     if (ret != NULL) {                                                                                                     
188       os::unmap_memory(rs.base(), rs.size());                                                                              
189     }                                                                                                                      
190     log_error(gc, init)("Error in mapping Old Gen to given AllocateOldGenAt = %s", AllocateOldGenAt);                      
191     os::close(_backing_fd);                                                                                                
192     return false;                                                                                                          
193   }                                                                                                                        
194 
195   os::close(_backing_fd);                                                                                                  
196   return true;                                                                                                             
197 }                                                                                                                          
198 
199 G1RegionToHeteroSpaceMapper::G1RegionToHeteroSpaceMapper(ReservedSpace rs,                                                 
200                                                          size_t actual_size,                                               
201                                                          size_t page_size,                                                 
202                                                          size_t alloc_granularity,                                         
203                                                          size_t commit_factor,                                             
204                                                          MemoryType type) :                                                
205   G1RegionToSpaceMapper(rs, actual_size, page_size, alloc_granularity, commit_factor, type),                               
206   _rs(rs),                                                                                                                 
                                                                                                                           
207   _num_committed_dram(0),                                                                                                  
208   _num_committed_nvdimm(0),                                                                                                
                                                                                                                           
209   _page_size(page_size),                                                                                                   
210   _commit_factor(commit_factor),                                                                                           
211   _type(type) {                                                                                                            
212   assert(actual_size == 2 * MaxHeapSize, "For 2-way heterogenuous heap, reserved space is two times MaxHeapSize");         
213 }                                                                                                                          
214 
215 bool G1RegionToHeteroSpaceMapper::initialize() {                                                                           
216   // Since we need to re-map the reserved space - 'Xmx' to nv-dimm and 'Xmx' to dram, we need to release the reserved memor
217   // Because on some OSes (e.g. Windows) you cannot do a file mapping on memory reserved with regular mapping.             
218   os::release_memory(_rs.base(), _rs.size());                                                                              
219   // First half of size Xmx is for nv-dimm.                                                                                
220   ReservedSpace rs_nvdimm = _rs.first_part(MaxHeapSize);                                                                   
221   assert(rs_nvdimm.base() == _rs.base(), "We should get the same base address");                                           
222 
223   // Second half of reserved memory is mapped to dram.                                                                     
224   ReservedSpace rs_dram = _rs.last_part(MaxHeapSize);                                                                      
225 
226   assert(rs_dram.size() == rs_nvdimm.size() && rs_nvdimm.size() == MaxHeapSize, "They all should be same");                
227 

187     if (ret != NULL) {
188       os::unmap_memory(rs.base(), rs.size());
189     }
190     log_error(gc, init)("Error in mapping Old Gen to given AllocateOldGenAt = %s", AllocateOldGenAt);
191     os::close(_backing_fd);
192     return false;
193   }
194 
195   os::close(_backing_fd);
196   return true;
197 }
198 
199 G1RegionToHeteroSpaceMapper::G1RegionToHeteroSpaceMapper(ReservedSpace rs,
200                                                          size_t actual_size,
201                                                          size_t page_size,
202                                                          size_t alloc_granularity,
203                                                          size_t commit_factor,
204                                                          MemoryType type) :
205   G1RegionToSpaceMapper(rs, actual_size, page_size, alloc_granularity, commit_factor, type),
206   _rs(rs),
207   _dram_mapper(NULL),
208   _num_committed_dram(0),
209   _num_committed_nvdimm(0),
210   _start_index_of_dram(0),
211   _page_size(page_size),
212   _commit_factor(commit_factor),
213   _type(type) {
214   assert(actual_size == 2 * MaxHeapSize, "For 2-way heterogenuous heap, reserved space is two times MaxHeapSize");
215 }
216 
217 bool G1RegionToHeteroSpaceMapper::initialize() {
218   // Since we need to re-map the reserved space - 'Xmx' to nv-dimm and 'Xmx' to dram, we need to release the reserved memor
219   // Because on some OSes (e.g. Windows) you cannot do a file mapping on memory reserved with regular mapping.
220   os::release_memory(_rs.base(), _rs.size());
221   // First half of size Xmx is for nv-dimm.
222   ReservedSpace rs_nvdimm = _rs.first_part(MaxHeapSize);
223   assert(rs_nvdimm.base() == _rs.base(), "We should get the same base address");
224 
225   // Second half of reserved memory is mapped to dram.
226   ReservedSpace rs_dram = _rs.last_part(MaxHeapSize);
227 
228   assert(rs_dram.size() == rs_nvdimm.size() && rs_nvdimm.size() == MaxHeapSize, "They all should be same");
229 

230   if (base != rs_dram.base()) {                                                                                            
231     if (base != NULL) {                                                                                                    
232       os::release_memory(base, rs_dram.size());                                                                            
233     }                                                                                                                      
234     log_error(gc, init)("Error in re-mapping memory on dram during G1 heterogenous memory initialization");                
235     return false;                                                                                                          
236   }                                                                                                                        
237 
238   // We reserve and commit this entire space to NV-DIMM.                                                                   
239   if (!map_nvdimm_space(rs_nvdimm)) {                                                                                      
240     log_error(gc, init)("Error in re-mapping memory to nv-dimm during G1 heterogenous memory initialization");             
241     return false;                                                                                                          
242   }                                                                                                                        
243 
244   if (_region_granularity >= (_page_size * _commit_factor)) {                                                              
245     _dram_mapper = new G1RegionsLargerThanCommitSizeMapper(rs_dram, rs_dram.size(), _page_size, _region_granularity, _commi
246   } else {                                                                                                                 
247     _dram_mapper = new G1RegionsSmallerThanCommitSizeMapper(rs_dram, rs_dram.size(), _page_size, _region_granularity, _comm
248   }                                                                                                                        
249 
250   _start_index_of_nvdimm = 0;                                                                                              
251   _start_index_of_dram = (uint)(rs_nvdimm.size() / _region_granularity);                                                   
252   return true;                                                                                                             
253 }                                                                                                                          
254 
255 void G1RegionToHeteroSpaceMapper::commit_regions(uint start_idx, size_t num_regions, WorkGang* pretouch_gang) {            
256   uint end_idx = (start_idx + (uint)num_regions - 1);                                                                      
257 
258   uint num_dram = end_idx >= _start_index_of_dram ? MIN2((end_idx - _start_index_of_dram + 1), (uint)num_regions) : 0;     
259   uint num_nvdimm = (uint)num_regions - num_dram;                                                                          
260 
261   if (num_nvdimm > 0) {                                                                                                    
262     // We do not need to commit nv-dimm regions, since they are committed in the beginning.                                
263     _num_committed_nvdimm += num_nvdimm;                                                                                   
264   }                                                                                                                        
265   if (num_dram > 0) {                                                                                                      
266     _dram_mapper->commit_regions(start_idx > _start_index_of_dram ? (start_idx - _start_index_of_dram) : 0, num_dram, preto
267     _num_committed_dram += num_dram;                                                                                       
268   }                                                                                                                        
269 }                                                                                                                          

232   if (base != rs_dram.base()) {
233     if (base != NULL) {
234       os::release_memory(base, rs_dram.size());
235     }
236     log_error(gc, init)("Error in re-mapping memory on dram during G1 heterogenous memory initialization");
237     return false;
238   }
239 
240   // We reserve and commit this entire space to NV-DIMM.
241   if (!map_nvdimm_space(rs_nvdimm)) {
242     log_error(gc, init)("Error in re-mapping memory to nv-dimm during G1 heterogenous memory initialization");
243     return false;
244   }
245 
246   if (_region_granularity >= (_page_size * _commit_factor)) {
247     _dram_mapper = new G1RegionsLargerThanCommitSizeMapper(rs_dram, rs_dram.size(), _page_size, _region_granularity, _commi
248   } else {
249     _dram_mapper = new G1RegionsSmallerThanCommitSizeMapper(rs_dram, rs_dram.size(), _page_size, _region_granularity, _comm
250   }
251 

252   _start_index_of_dram = (uint)(rs_nvdimm.size() / _region_granularity);
253   return true;
254 }
255 
256 void G1RegionToHeteroSpaceMapper::commit_regions(uint start_idx, size_t num_regions, WorkGang* pretouch_gang) {
257   uint end_idx = (start_idx + (uint)num_regions - 1);
258 
259   uint num_dram = end_idx >= _start_index_of_dram ? MIN2((end_idx - _start_index_of_dram + 1), (uint)num_regions) : 0;
260   uint num_nvdimm = (uint)num_regions - num_dram;
261 
262   if (num_nvdimm > 0) {
263     // We do not need to commit nv-dimm regions, since they are committed in the beginning.
264     _num_committed_nvdimm += num_nvdimm;
265   }
266   if (num_dram > 0) {
267     _dram_mapper->commit_regions(start_idx > _start_index_of_dram ? (start_idx - _start_index_of_dram) : 0, num_dram, preto
268     _num_committed_dram += num_dram;
269   }
270 }
< prev index next >