< prev index next >

src/hotspot/share/asm/assembler.cpp


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 
24 #include "precompiled.hpp"                                                                                                           
25 #include "asm/codeBuffer.hpp"                                                                                                        
26 #include "asm/macroAssembler.hpp"                                                                                                    
27 #include "asm/macroAssembler.inline.hpp"                                                                                             
                                                                                                                                     
28 #include "runtime/atomic.hpp"                                                                                                        
29 #include "runtime/icache.hpp"                                                                                                        
30 #include "runtime/os.hpp"                                                                                                            
31 #include "runtime/thread.hpp"                                                                                                        
32 
33 
34 // Implementation of AbstractAssembler                                                                                               
35 //                                                                                                                                   
36 // The AbstractAssembler is generating code into a CodeBuffer. To make code generation faster,                                       
37 // the assembler keeps a copy of the code buffers boundaries & modifies them when                                                    
38 // emitting bytes rather than using the code buffers accessor functions all the time.                                                
39 // The code buffer is updated via set_code_end(...) after emitting a whole instruction.                                              
40 
41 AbstractAssembler::AbstractAssembler(CodeBuffer* code) {                                                                             
42   if (code == NULL)  return;                                                                                                         
43   CodeSection* cs = code->insts();                                                                                                   
44   cs->clear_mark();   // new assembler kills old mark                                                                                
45   if (cs->start() == NULL)  {                                                                                                        
46     vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "CodeCache: no room for %s", code->name());                                             

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 
24 #include "precompiled.hpp"
25 #include "asm/codeBuffer.hpp"
26 #include "asm/macroAssembler.hpp"
27 #include "asm/macroAssembler.inline.hpp"
28 #include "gc/shared/collectedHeap.hpp"
29 #include "runtime/atomic.hpp"
30 #include "runtime/icache.hpp"
31 #include "runtime/os.hpp"
32 #include "runtime/thread.hpp"
33 
34 
35 // Implementation of AbstractAssembler
36 //
37 // The AbstractAssembler is generating code into a CodeBuffer. To make code generation faster,
38 // the assembler keeps a copy of the code buffers boundaries & modifies them when
39 // emitting bytes rather than using the code buffers accessor functions all the time.
40 // The code buffer is updated via set_code_end(...) after emitting a whole instruction.
41 
42 AbstractAssembler::AbstractAssembler(CodeBuffer* code) {
43   if (code == NULL)  return;
44   CodeSection* cs = code->insts();
45   cs->clear_mark();   // new assembler kills old mark
46   if (cs->start() == NULL)  {
47     vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "CodeCache: no room for %s", code->name());

289   DelayedConstant* dcon = DelayedConstant::add(T_ADDRESS, (DelayedConstant::value_fn_t) value_fn);                                   
290   return &dcon->value;                                                                                                               
291 }                                                                                                                                    
292 void AbstractAssembler::update_delayed_values() {                                                                                    
293   DelayedConstant::update_all();                                                                                                     
294 }                                                                                                                                    
295 
296 void AbstractAssembler::block_comment(const char* comment) {                                                                         
297   if (sect() == CodeBuffer::SECT_INSTS) {                                                                                            
298     code_section()->outer()->block_comment(offset(), comment);                                                                       
299   }                                                                                                                                  
300 }                                                                                                                                    
301 
302 const char* AbstractAssembler::code_string(const char* str) {                                                                        
303   if (sect() == CodeBuffer::SECT_INSTS || sect() == CodeBuffer::SECT_STUBS) {                                                        
304     return code_section()->outer()->code_string(str);                                                                                
305   }                                                                                                                                  
306   return NULL;                                                                                                                       
307 }                                                                                                                                    
308 
309 bool MacroAssembler::needs_explicit_null_check(intptr_t offset) {                                                                    
310   // Exception handler checks the nmethod's implicit null checks table                                                               
311   // only when this method returns false.                                                                                            
                                                                                                                                     
                                                                                                                                     
312 #ifdef _LP64                                                                                                                         
313   if (UseCompressedOops && Universe::narrow_oop_base() != NULL) {                                                                    
314     assert (Universe::heap() != NULL, "java heap should be initialized");                                                            
315     // The first page after heap_base is unmapped and                                                                                
316     // the 'offset' is equal to [heap_base + offset] for                                                                             
317     // narrow oop implicit null checks.                                                                                              
318     uintptr_t base = (uintptr_t)Universe::narrow_oop_base();                                                                         
319     if ((uintptr_t)offset >= base) {                                                                                                 
320       // Normalize offset for the next check.                                                                                        
321       offset = (intptr_t)(pointer_delta((void*)offset, (void*)base, 1));                                                             
322     }                                                                                                                                
323   }                                                                                                                                  
324 #endif                                                                                                                               
325   return offset < 0 || os::vm_page_size() <= offset;                                                                                 
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
326 }                                                                                                                                    

290   DelayedConstant* dcon = DelayedConstant::add(T_ADDRESS, (DelayedConstant::value_fn_t) value_fn);
291   return &dcon->value;
292 }
293 void AbstractAssembler::update_delayed_values() {
294   DelayedConstant::update_all();
295 }
296 
297 void AbstractAssembler::block_comment(const char* comment) {
298   if (sect() == CodeBuffer::SECT_INSTS) {
299     code_section()->outer()->block_comment(offset(), comment);
300   }
301 }
302 
303 const char* AbstractAssembler::code_string(const char* str) {
304   if (sect() == CodeBuffer::SECT_INSTS || sect() == CodeBuffer::SECT_STUBS) {
305     return code_section()->outer()->code_string(str);
306   }
307   return NULL;
308 }
309 
310 bool MacroAssembler::uses_implicit_null_check(void* address) {
311   // Exception handler checks the nmethod's implicit null checks table
312   // only when this method returns false.
313   intptr_t cell_header_size = Universe::heap()->cell_header_size();
314   HeapWord* start = (HeapWord*)-cell_header_size;
315 #ifdef _LP64
316   if (UseCompressedOops && Universe::narrow_oop_base() != NULL) {

317     // The first page after heap_base is unmapped and
318     // the 'offset' is equal to [heap_base + offset] for
319     // narrow oop implicit null checks.
320     start += (uintptr_t)Universe::narrow_oop_base();




321   }
322 #endif
323   MemRegion implicit_null_range(start, (os::vm_page_size() + cell_header_size) / HeapWordSize);
324   return implicit_null_range.contains(address);
325 }
326 
327 bool MacroAssembler::needs_explicit_null_check(intptr_t offset) {
328   // Check if offset is outside of [-cell_header_size, os::vm_page_size)
329   return offset < -Universe::heap()->cell_header_size() ||
330          offset >= os::vm_page_size();
331 }
< prev index next >