duke@435: /* duke@435: * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: inline void AbstractAssembler::sync() { duke@435: CodeSection* cs = code_section(); duke@435: guarantee(cs->start() == _code_begin, "must not shift code buffer"); duke@435: cs->set_end(_code_pos); duke@435: } duke@435: duke@435: inline void AbstractAssembler::emit_byte(int x) { duke@435: assert(isByte(x), "not a byte"); duke@435: *(unsigned char*)_code_pos = (unsigned char)x; duke@435: _code_pos += sizeof(unsigned char); duke@435: sync(); duke@435: } duke@435: duke@435: duke@435: inline void AbstractAssembler::emit_word(int x) { duke@435: *(short*)_code_pos = (short)x; duke@435: _code_pos += sizeof(short); duke@435: sync(); duke@435: } duke@435: duke@435: duke@435: inline void AbstractAssembler::emit_long(jint x) { duke@435: *(jint*)_code_pos = x; duke@435: _code_pos += sizeof(jint); duke@435: sync(); duke@435: } duke@435: duke@435: inline void AbstractAssembler::emit_address(address x) { duke@435: *(address*)_code_pos = x; duke@435: _code_pos += sizeof(address); duke@435: sync(); duke@435: } duke@435: duke@435: inline address AbstractAssembler::inst_mark() const { duke@435: return code_section()->mark(); duke@435: } duke@435: duke@435: duke@435: inline void AbstractAssembler::set_inst_mark() { duke@435: code_section()->set_mark(); duke@435: } duke@435: duke@435: duke@435: inline void AbstractAssembler::clear_inst_mark() { duke@435: code_section()->clear_mark(); duke@435: } duke@435: duke@435: duke@435: inline void AbstractAssembler::relocate(RelocationHolder const& rspec, int format) { duke@435: assert(!pd_check_instruction_mark() duke@435: || inst_mark() == NULL || inst_mark() == _code_pos, duke@435: "call relocate() between instructions"); duke@435: code_section()->relocate(_code_pos, rspec, format); duke@435: } duke@435: duke@435: duke@435: inline CodeBuffer* AbstractAssembler::code() const { duke@435: return code_section()->outer(); duke@435: } duke@435: duke@435: inline int AbstractAssembler::sect() const { duke@435: return code_section()->index(); duke@435: } duke@435: duke@435: inline int AbstractAssembler::locator() const { duke@435: return CodeBuffer::locator(offset(), sect()); duke@435: } duke@435: duke@435: inline address AbstractAssembler::target(Label& L) { duke@435: return code_section()->target(L, pc()); duke@435: } duke@435: duke@435: inline int Label::loc_pos() const { duke@435: return CodeBuffer::locator_pos(loc()); duke@435: } duke@435: duke@435: inline int Label::loc_sect() const { duke@435: return CodeBuffer::locator_sect(loc()); duke@435: } duke@435: duke@435: inline void Label::bind_loc(int pos, int sect) { duke@435: bind_loc(CodeBuffer::locator(pos, sect)); duke@435: } duke@435: duke@435: address AbstractAssembler::address_constant(Label& L) { duke@435: address c = NULL; duke@435: address ptr = start_a_const(sizeof(c), sizeof(c)); duke@435: if (ptr != NULL) { duke@435: relocate(Relocation::spec_simple(relocInfo::internal_word_type)); duke@435: *(address*)ptr = c = code_section()->target(L, ptr); duke@435: _code_pos = ptr + sizeof(c); duke@435: end_a_const(); duke@435: } duke@435: return ptr; duke@435: } duke@435: duke@435: address AbstractAssembler::address_table_constant(GrowableArray labels) { duke@435: int addressSize = sizeof(address); duke@435: int sizeLabel = addressSize * labels.length(); duke@435: address ptr = start_a_const(sizeLabel, addressSize); duke@435: duke@435: if (ptr != NULL) { duke@435: address *labelLoc = (address*)ptr; duke@435: for (int i=0; i < labels.length(); i++) { duke@435: emit_address(code_section()->target(*labels.at(i), (address)&labelLoc[i])); duke@435: code_section()->relocate((address)&labelLoc[i], relocInfo::internal_word_type); duke@435: } duke@435: end_a_const(); duke@435: } duke@435: return ptr; duke@435: }