hotspot/src/share/vm/asm/assembler.inline.hpp
author trims
Thu, 27 May 2010 19:08:38 -0700
changeset 5547 f4b087cbb361
parent 1 489c9b5090e2
child 7397 5b173b4ca846
permissions -rw-r--r--
6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
     2
 * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
inline void AbstractAssembler::sync() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
  CodeSection* cs = code_section();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
  guarantee(cs->start() == _code_begin, "must not shift code buffer");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
  cs->set_end(_code_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
inline void AbstractAssembler::emit_byte(int x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  assert(isByte(x), "not a byte");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  *(unsigned char*)_code_pos = (unsigned char)x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  _code_pos += sizeof(unsigned char);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  sync();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
inline void AbstractAssembler::emit_word(int x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  *(short*)_code_pos = (short)x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  _code_pos += sizeof(short);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  sync();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
inline void AbstractAssembler::emit_long(jint x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  *(jint*)_code_pos = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  _code_pos += sizeof(jint);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  sync();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
inline void AbstractAssembler::emit_address(address x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  *(address*)_code_pos = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  _code_pos += sizeof(address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  sync();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
inline address AbstractAssembler::inst_mark() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  return code_section()->mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
inline void AbstractAssembler::set_inst_mark() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  code_section()->set_mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
inline void AbstractAssembler::clear_inst_mark() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  code_section()->clear_mark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
inline void AbstractAssembler::relocate(RelocationHolder const& rspec, int format) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  assert(!pd_check_instruction_mark()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
         || inst_mark() == NULL || inst_mark() == _code_pos,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
         "call relocate() between instructions");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  code_section()->relocate(_code_pos, rspec, format);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
inline CodeBuffer* AbstractAssembler::code() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  return code_section()->outer();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
inline int AbstractAssembler::sect() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  return code_section()->index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
inline int AbstractAssembler::locator() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  return CodeBuffer::locator(offset(), sect());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
inline address AbstractAssembler::target(Label& L) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  return code_section()->target(L, pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
inline int Label::loc_pos() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  return CodeBuffer::locator_pos(loc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
inline int Label::loc_sect() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  return CodeBuffer::locator_sect(loc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
inline void Label::bind_loc(int pos, int sect) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  bind_loc(CodeBuffer::locator(pos, sect));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
address AbstractAssembler::address_constant(Label& L) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  address c = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  address ptr = start_a_const(sizeof(c), sizeof(c));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  if (ptr != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    relocate(Relocation::spec_simple(relocInfo::internal_word_type));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    *(address*)ptr = c = code_section()->target(L, ptr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
    _code_pos = ptr + sizeof(c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    end_a_const();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  return ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
address AbstractAssembler::address_table_constant(GrowableArray<Label*> labels) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  int addressSize = sizeof(address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  int sizeLabel = addressSize * labels.length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  address ptr = start_a_const(sizeLabel, addressSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  if (ptr != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    address *labelLoc = (address*)ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
    for (int i=0; i < labels.length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      emit_address(code_section()->target(*labels.at(i), (address)&labelLoc[i]));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      code_section()->relocate((address)&labelLoc[i], relocInfo::internal_word_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    end_a_const();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  return ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
}