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