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

changeset 435
a61af66fc99e
child 1907
c18cbe5936b8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/asm/assembler.inline.hpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,135 @@
     1.4 +/*
     1.5 + * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +inline void AbstractAssembler::sync() {
    1.29 +  CodeSection* cs = code_section();
    1.30 +  guarantee(cs->start() == _code_begin, "must not shift code buffer");
    1.31 +  cs->set_end(_code_pos);
    1.32 +}
    1.33 +
    1.34 +inline void AbstractAssembler::emit_byte(int x) {
    1.35 +  assert(isByte(x), "not a byte");
    1.36 +  *(unsigned char*)_code_pos = (unsigned char)x;
    1.37 +  _code_pos += sizeof(unsigned char);
    1.38 +  sync();
    1.39 +}
    1.40 +
    1.41 +
    1.42 +inline void AbstractAssembler::emit_word(int x) {
    1.43 +  *(short*)_code_pos = (short)x;
    1.44 +  _code_pos += sizeof(short);
    1.45 +  sync();
    1.46 +}
    1.47 +
    1.48 +
    1.49 +inline void AbstractAssembler::emit_long(jint x) {
    1.50 +  *(jint*)_code_pos = x;
    1.51 +  _code_pos += sizeof(jint);
    1.52 +  sync();
    1.53 +}
    1.54 +
    1.55 +inline void AbstractAssembler::emit_address(address x) {
    1.56 +  *(address*)_code_pos = x;
    1.57 +  _code_pos += sizeof(address);
    1.58 +  sync();
    1.59 +}
    1.60 +
    1.61 +inline address AbstractAssembler::inst_mark() const {
    1.62 +  return code_section()->mark();
    1.63 +}
    1.64 +
    1.65 +
    1.66 +inline void AbstractAssembler::set_inst_mark() {
    1.67 +  code_section()->set_mark();
    1.68 +}
    1.69 +
    1.70 +
    1.71 +inline void AbstractAssembler::clear_inst_mark() {
    1.72 +  code_section()->clear_mark();
    1.73 +}
    1.74 +
    1.75 +
    1.76 +inline void AbstractAssembler::relocate(RelocationHolder const& rspec, int format) {
    1.77 +  assert(!pd_check_instruction_mark()
    1.78 +         || inst_mark() == NULL || inst_mark() == _code_pos,
    1.79 +         "call relocate() between instructions");
    1.80 +  code_section()->relocate(_code_pos, rspec, format);
    1.81 +}
    1.82 +
    1.83 +
    1.84 +inline CodeBuffer* AbstractAssembler::code() const {
    1.85 +  return code_section()->outer();
    1.86 +}
    1.87 +
    1.88 +inline int AbstractAssembler::sect() const {
    1.89 +  return code_section()->index();
    1.90 +}
    1.91 +
    1.92 +inline int AbstractAssembler::locator() const {
    1.93 +  return CodeBuffer::locator(offset(), sect());
    1.94 +}
    1.95 +
    1.96 +inline address AbstractAssembler::target(Label& L) {
    1.97 +  return code_section()->target(L, pc());
    1.98 +}
    1.99 +
   1.100 +inline int Label::loc_pos() const {
   1.101 +  return CodeBuffer::locator_pos(loc());
   1.102 +}
   1.103 +
   1.104 +inline int Label::loc_sect() const {
   1.105 +  return CodeBuffer::locator_sect(loc());
   1.106 +}
   1.107 +
   1.108 +inline void Label::bind_loc(int pos, int sect) {
   1.109 +  bind_loc(CodeBuffer::locator(pos, sect));
   1.110 +}
   1.111 +
   1.112 +address AbstractAssembler::address_constant(Label& L) {
   1.113 +  address c = NULL;
   1.114 +  address ptr = start_a_const(sizeof(c), sizeof(c));
   1.115 +  if (ptr != NULL) {
   1.116 +    relocate(Relocation::spec_simple(relocInfo::internal_word_type));
   1.117 +    *(address*)ptr = c = code_section()->target(L, ptr);
   1.118 +    _code_pos = ptr + sizeof(c);
   1.119 +    end_a_const();
   1.120 +  }
   1.121 +  return ptr;
   1.122 +}
   1.123 +
   1.124 +address AbstractAssembler::address_table_constant(GrowableArray<Label*> labels) {
   1.125 +  int addressSize = sizeof(address);
   1.126 +  int sizeLabel = addressSize * labels.length();
   1.127 +  address ptr = start_a_const(sizeLabel, addressSize);
   1.128 +
   1.129 +  if (ptr != NULL) {
   1.130 +    address *labelLoc = (address*)ptr;
   1.131 +    for (int i=0; i < labels.length(); i++) {
   1.132 +      emit_address(code_section()->target(*labels.at(i), (address)&labelLoc[i]));
   1.133 +      code_section()->relocate((address)&labelLoc[i], relocInfo::internal_word_type);
   1.134 +    }
   1.135 +    end_a_const();
   1.136 +  }
   1.137 +  return ptr;
   1.138 +}

mercurial