assembler.hpp revision 3932
2120N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A// This file contains platform-independent assembler declarations. 2312N/A * Labels represent destinations for control transfer instructions. Such 2312N/A * instructions can accept a Label as their target argument. A Label is 2312N/A * bound to the current location in the code stream by calling the 0N/A * MacroAssembler's 'bind' method, which in turn calls the Label's 'bind' 0N/A * method. A Label may be referenced by an instruction before it's bound 0N/A * (i.e., 'forward referenced'). 'bind' stores the current code offset 0N/A * in the Label object. 0N/A * If an instruction references a bound Label, the offset field(s) within 0N/A * the instruction are immediately filled in based on the Label's code 2312N/A * offset. If an instruction references an unbound label, that 2312N/A * instruction is put on a list of instructions that must be patched 0N/A * (i.e., 'resolved') when the Label is bound. 2312N/A * 'bind' will call the platform-specific 'patch_instruction' method to 2312N/A * fill in the offset field(s) for each unresolved instruction (if there 2312N/A * are any). 'patch_instruction' lives in one of the 0N/A * Instead of using a linked list of unresolved instructions, a Label has 0N/A * an array of unresolved instruction code offsets. _patch_index 0N/A * contains the total number of forward references. If the Label's array 0N/A * overflows (i.e., _patch_index grows larger than the array size), a 0N/A * GrowableArray is allocated to hold the remaining offsets. (The cache 0N/A * size is 4 for now, which handles over 99.5% of the cases) 0N/A * Labels may only be used within a single CodeSection. If you need 0N/A * to create references between code sections, use explicit relocations. 0N/A // _loc encodes both the binding state (via its sign) 0N/A // and the binding locator (via its value) of a label. 0N/A // _loc >= 0 bound label, loc() encodes the target (jump) position 0N/A // _loc == -1 unbound label 0N/A // References to instructions that jump to this unresolved label. 0N/A // These instructions need to be patched when the label is bound 0N/A // using the platform-specific patchInstruction() method. 0N/A // To avoid having to allocate from the C-heap each time, we provide 0N/A // a local cache and use the overflow only if we exceed the local cache 0N/A * After binding, be sure 'patch_instructions' is called later to link 0N/A // Iterates over all unresolved instructions for printing 0N/A * Returns the position of the the Label in the code buffer 0N/A * The position is a 'locator', which encodes both offset and section. 0N/A * Adds a reference to an unresolved displacement instruction to 0N/A * this unbound label 0N/A * @param cb the code buffer being patched 0N/A * @param branch_loc the locator of the branch instruction in the code buffer 0N/A * Iterate over the list of patches, resolving the instructions 0N/A * Call patch_instruction on each 'branch_loc' value 0N/A// A union type for code which has to assemble both constant and 0N/A// non-constant operands, when the distinction cannot be made 0N/A// The Abstract Assembler: Pure assembler doing NO optimizations on the 0N/A// instruction level; i.e., what you write is what you get. 0N/A// The Assembler is generating code into a CodeBuffer. 367N/A // Code emission & accessing 0N/A // This routine is called with a label is used for an address. 0N/A // Labels and displacements truck in offsets, but target must return a PC. 2312N/A bool is8bit(
int x)
const {
return -
0x80 <= x && x <
0x80; }
2312N/A // Instruction boundaries (required when emitting relocatable values). 0N/A // Make it return true on platforms which need to verify 0N/A // instruction boundaries for some operations. 0N/A // Add delta to short branch distance to verify that it still fit into imm8. 0N/A // save end pointer back to code buf. 0N/A // min and max values for signed immediate ranges 0N/A // Test if x is within signed immediate range for nbits 2442N/A int sect()
const;
// return _code_section->index() 0N/A // Constants in code 0N/A // Associate a comment with the current offset. It will be printed 0N/A // along with the disassembly when printing nmethods. Currently 0N/A // only supported in the instruction section of the code buffer. 0N/A void bind(
Label& L);
// binds an unbound label L to the current code position 0N/A // Move to a different section in the same code buffer. 0N/A // Inform assembler when generating stub code and relocation info 39N/A // Ditto for constants. 0N/A // constants support 0N/A // Bootstrapping aid to cope with delayed determination of constants. 0N/A // Returns a static address which will eventually contain the constant. 0N/A // The value zero (NULL) stands instead of a constant which is still uncomputed. 0N/A // Thus, the eventual value of the constant must not be zero. 0N/A // This is fine, since this is designed for embedding object field 0N/A // offsets in code which must be generated before the object class is loaded. 0N/A // Field offsets are never zero, since an object's header (mark word) 0N/A // is located at offset zero. 0N/A // Last overloading is platform-dependent; look in assembler_<arch>.cpp. 0N/A // Bang stack to trigger StackOverflowError at a safe location 0N/A // implementation delegates to machine-specific bang_stack_with_offset 0N/A * A platform-dependent method to patch a jump instruction that refers 0N/A * @param branch the location of the instruction to patch 0N/A * @param masm the assembler which generated the branch 2312N/A * Platform-dependent method of printing an instruction that needs to be 0N/A * @param branch the instruction to be patched in the buffer. 0N/A#
endif // SHARE_VM_ASM_ASSEMBLER_HPP