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