src/share/vm/asm/assembler.inline.hpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

Initial load

     1 /*
     2  * Copyright 1997-2006 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  *
    23  */
    25 inline void AbstractAssembler::sync() {
    26   CodeSection* cs = code_section();
    27   guarantee(cs->start() == _code_begin, "must not shift code buffer");
    28   cs->set_end(_code_pos);
    29 }
    31 inline void AbstractAssembler::emit_byte(int x) {
    32   assert(isByte(x), "not a byte");
    33   *(unsigned char*)_code_pos = (unsigned char)x;
    34   _code_pos += sizeof(unsigned char);
    35   sync();
    36 }
    39 inline void AbstractAssembler::emit_word(int x) {
    40   *(short*)_code_pos = (short)x;
    41   _code_pos += sizeof(short);
    42   sync();
    43 }
    46 inline void AbstractAssembler::emit_long(jint x) {
    47   *(jint*)_code_pos = x;
    48   _code_pos += sizeof(jint);
    49   sync();
    50 }
    52 inline void AbstractAssembler::emit_address(address x) {
    53   *(address*)_code_pos = x;
    54   _code_pos += sizeof(address);
    55   sync();
    56 }
    58 inline address AbstractAssembler::inst_mark() const {
    59   return code_section()->mark();
    60 }
    63 inline void AbstractAssembler::set_inst_mark() {
    64   code_section()->set_mark();
    65 }
    68 inline void AbstractAssembler::clear_inst_mark() {
    69   code_section()->clear_mark();
    70 }
    73 inline void AbstractAssembler::relocate(RelocationHolder const& rspec, int format) {
    74   assert(!pd_check_instruction_mark()
    75          || inst_mark() == NULL || inst_mark() == _code_pos,
    76          "call relocate() between instructions");
    77   code_section()->relocate(_code_pos, rspec, format);
    78 }
    81 inline CodeBuffer* AbstractAssembler::code() const {
    82   return code_section()->outer();
    83 }
    85 inline int AbstractAssembler::sect() const {
    86   return code_section()->index();
    87 }
    89 inline int AbstractAssembler::locator() const {
    90   return CodeBuffer::locator(offset(), sect());
    91 }
    93 inline address AbstractAssembler::target(Label& L) {
    94   return code_section()->target(L, pc());
    95 }
    97 inline int Label::loc_pos() const {
    98   return CodeBuffer::locator_pos(loc());
    99 }
   101 inline int Label::loc_sect() const {
   102   return CodeBuffer::locator_sect(loc());
   103 }
   105 inline void Label::bind_loc(int pos, int sect) {
   106   bind_loc(CodeBuffer::locator(pos, sect));
   107 }
   109 address AbstractAssembler::address_constant(Label& L) {
   110   address c = NULL;
   111   address ptr = start_a_const(sizeof(c), sizeof(c));
   112   if (ptr != NULL) {
   113     relocate(Relocation::spec_simple(relocInfo::internal_word_type));
   114     *(address*)ptr = c = code_section()->target(L, ptr);
   115     _code_pos = ptr + sizeof(c);
   116     end_a_const();
   117   }
   118   return ptr;
   119 }
   121 address AbstractAssembler::address_table_constant(GrowableArray<Label*> labels) {
   122   int addressSize = sizeof(address);
   123   int sizeLabel = addressSize * labels.length();
   124   address ptr = start_a_const(sizeLabel, addressSize);
   126   if (ptr != NULL) {
   127     address *labelLoc = (address*)ptr;
   128     for (int i=0; i < labels.length(); i++) {
   129       emit_address(code_section()->target(*labels.at(i), (address)&labelLoc[i]));
   130       code_section()->relocate((address)&labelLoc[i], relocInfo::internal_word_type);
   131     }
   132     end_a_const();
   133   }
   134   return ptr;
   135 }

mercurial