< prev index next >

src/hotspot/share/asm/assembler.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2017, 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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "asm/codeBuffer.hpp"
  27 #include "asm/macroAssembler.hpp"
  28 #include "asm/macroAssembler.inline.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());
  48   }
  49   _code_section = cs;
  50   _oop_recorder= code->oop_recorder();
  51   DEBUG_ONLY( _short_branch_delta = 0; )
  52 }


 283 void AbstractAssembler::update_delayed_values() {
 284   DelayedConstant::update_all();
 285 }
 286 
 287 void AbstractAssembler::block_comment(const char* comment) {
 288   if (sect() == CodeBuffer::SECT_INSTS) {
 289     code_section()->outer()->block_comment(offset(), comment);
 290   }
 291 }
 292 
 293 const char* AbstractAssembler::code_string(const char* str) {
 294   if (sect() == CodeBuffer::SECT_INSTS || sect() == CodeBuffer::SECT_STUBS) {
 295     return code_section()->outer()->code_string(str);
 296   }
 297   return NULL;
 298 }
 299 
 300 bool MacroAssembler::needs_explicit_null_check(intptr_t offset) {
 301   // Exception handler checks the nmethod's implicit null checks table
 302   // only when this method returns false.








 303 #ifdef _LP64
 304   if (UseCompressedOops && Universe::narrow_oop_base() != NULL) {
 305     assert (Universe::heap() != NULL, "java heap should be initialized");
 306     // The first page after heap_base is unmapped and
 307     // the 'offset' is equal to [heap_base + offset] for
 308     // narrow oop implicit null checks.
 309     uintptr_t base = (uintptr_t)Universe::narrow_oop_base();
 310     if ((uintptr_t)offset >= base) {







 311       // Normalize offset for the next check.
 312       offset = (intptr_t)(pointer_delta((void*)offset, (void*)base, 1));
 313     }
 314   }
 315 #endif







 316   return offset < 0 || os::vm_page_size() <= offset;
 317 }
   1 /*
   2  * Copyright (c) 1997, 2018, 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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "asm/codeBuffer.hpp"
  27 #include "asm/macroAssembler.hpp"
  28 #include "asm/macroAssembler.inline.hpp"
  29 #include "runtime/atomic.hpp"
  30 #include "runtime/icache.hpp"
  31 #include "runtime/os.hpp"
  32 #include "runtime/thread.hpp"
  33 #include "utilities/macros.hpp"
  34 #if INCLUDE_SHENANDOAHGC
  35 #include "gc/shenandoah/shenandoahBarrierSetAssembler.hpp"
  36 #endif
  37 
  38 
  39 // Implementation of AbstractAssembler
  40 //
  41 // The AbstractAssembler is generating code into a CodeBuffer. To make code generation faster,
  42 // the assembler keeps a copy of the code buffers boundaries & modifies them when
  43 // emitting bytes rather than using the code buffers accessor functions all the time.
  44 // The code buffer is updated via set_code_end(...) after emitting a whole instruction.
  45 
  46 AbstractAssembler::AbstractAssembler(CodeBuffer* code) {
  47   if (code == NULL)  return;
  48   CodeSection* cs = code->insts();
  49   cs->clear_mark();   // new assembler kills old mark
  50   if (cs->start() == NULL)  {
  51     vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "CodeCache: no room for %s", code->name());
  52   }
  53   _code_section = cs;
  54   _oop_recorder= code->oop_recorder();
  55   DEBUG_ONLY( _short_branch_delta = 0; )
  56 }


 287 void AbstractAssembler::update_delayed_values() {
 288   DelayedConstant::update_all();
 289 }
 290 
 291 void AbstractAssembler::block_comment(const char* comment) {
 292   if (sect() == CodeBuffer::SECT_INSTS) {
 293     code_section()->outer()->block_comment(offset(), comment);
 294   }
 295 }
 296 
 297 const char* AbstractAssembler::code_string(const char* str) {
 298   if (sect() == CodeBuffer::SECT_INSTS || sect() == CodeBuffer::SECT_STUBS) {
 299     return code_section()->outer()->code_string(str);
 300   }
 301   return NULL;
 302 }
 303 
 304 bool MacroAssembler::needs_explicit_null_check(intptr_t offset) {
 305   // Exception handler checks the nmethod's implicit null checks table
 306   // only when this method returns false.
 307 #ifdef AARCH64
 308   // AArch64 addresses passed from the signal handler may have
 309   // their top 8 bits zeroed. That affects the case where
 310   // Shenandoah tries to load a Brooks pointer via a null oop.
 311   const uintptr_t address_bits = (uintptr_t)0xfffffffffffful;
 312 #else
 313   const uintptr_t address_bits = ~(uintptr_t)0;
 314 #endif
 315 #ifdef _LP64
 316   if (UseCompressedOops && Universe::narrow_oop_base() != NULL) {
 317     assert (Universe::heap() != NULL, "java heap should be initialized");
 318     // The first page after heap_base is unmapped and
 319     // the 'offset' is equal to [heap_base + offset] for
 320     // narrow oop implicit null checks.
 321     uintptr_t base = (uintptr_t)Universe::narrow_oop_base();
 322     int adj = 0;
 323 #if INCLUDE_SHENANDOAHGC
 324     if (UseShenandoahGC) {
 325       adj = ShenandoahBrooksPointer::byte_offset();
 326       assert(adj < 0, "no need for positive adjustments");
 327     }
 328 #endif
 329     if ((uintptr_t)((offset - adj) & address_bits) >= base) {
 330       // Normalize offset for the next check.
 331       offset = (intptr_t)(pointer_delta((void*)offset, (void*)base, 1));
 332     }
 333   }
 334 #endif
 335 
 336 #if INCLUDE_SHENANDOAHGC
 337   if (UseShenandoahGC && ((offset & address_bits) == (ShenandoahBrooksPointer::byte_offset() & address_bits))) {
 338     return false;
 339   }
 340 #endif
 341 
 342   return offset < 0 || os::vm_page_size() <= offset;
 343 }
< prev index next >