aboutsummaryrefslogtreecommitdiff
path: root/src/share/vm/asm/assembler.inline.hpp
blob: a42b6d3ab8a85924077b37f2031b83b150449c82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

#ifndef SHARE_VM_ASM_ASSEMBLER_INLINE_HPP
#define SHARE_VM_ASM_ASSEMBLER_INLINE_HPP

#include "asm/assembler.hpp"
#include "asm/codeBuffer.hpp"
#include "compiler/disassembler.hpp"
#include "runtime/threadLocalStorage.hpp"

inline void AbstractAssembler::sync() {
  CodeSection* cs = code_section();
  guarantee(cs->start() == _code_begin, "must not shift code buffer");
  cs->set_end(_code_pos);
}

inline void AbstractAssembler::emit_byte(int x) {
  assert(isByte(x), "not a byte");
  *(unsigned char*)_code_pos = (unsigned char)x;
  _code_pos += sizeof(unsigned char);
  sync();
}


inline void AbstractAssembler::emit_word(int x) {
  *(short*)_code_pos = (short)x;
  _code_pos += sizeof(short);
  sync();
}


inline void AbstractAssembler::emit_long(jint x) {
  *(jint*)_code_pos = x;
  _code_pos += sizeof(jint);
  sync();
}

inline void AbstractAssembler::emit_address(address x) {
  *(address*)_code_pos = x;
  _code_pos += sizeof(address);
  sync();
}

inline address AbstractAssembler::inst_mark() const {
  return code_section()->mark();
}


inline void AbstractAssembler::set_inst_mark() {
  code_section()->set_mark();
}


inline void AbstractAssembler::clear_inst_mark() {
  code_section()->clear_mark();
}


inline void AbstractAssembler::relocate(RelocationHolder const& rspec, int format) {
  assert(!pd_check_instruction_mark()
         || inst_mark() == NULL || inst_mark() == _code_pos,
         "call relocate() between instructions");
  code_section()->relocate(_code_pos, rspec, format);
}


inline CodeBuffer* AbstractAssembler::code() const {
  return code_section()->outer();
}

inline int AbstractAssembler::sect() const {
  return code_section()->index();
}

inline int AbstractAssembler::locator() const {
  return CodeBuffer::locator(offset(), sect());
}

inline address AbstractAssembler::target(Label& L) {
  return code_section()->target(L, pc());
}

inline int Label::loc_pos() const {
  return CodeBuffer::locator_pos(loc());
}

inline int Label::loc_sect() const {
  return CodeBuffer::locator_sect(loc());
}

inline void Label::bind_loc(int pos, int sect) {
  bind_loc(CodeBuffer::locator(pos, sect));
}

address AbstractAssembler::address_constant(Label& L) {
  address c = NULL;
  address ptr = start_a_const(sizeof(c), sizeof(c));
  if (ptr != NULL) {
    relocate(Relocation::spec_simple(relocInfo::internal_word_type));
    *(address*)ptr = c = code_section()->target(L, ptr);
    _code_pos = ptr + sizeof(c);
    end_a_const();
  }
  return ptr;
}

address AbstractAssembler::address_table_constant(GrowableArray<Label*> labels) {
  int addressSize = sizeof(address);
  int sizeLabel = addressSize * labels.length();
  address ptr = start_a_const(sizeLabel, addressSize);

  if (ptr != NULL) {
    address *labelLoc = (address*)ptr;
    for (int i=0; i < labels.length(); i++) {
      emit_address(code_section()->target(*labels.at(i), (address)&labelLoc[i]));
      code_section()->relocate((address)&labelLoc[i], relocInfo::internal_word_type);
    }
    end_a_const();
  }
  return ptr;
}

#endif // SHARE_VM_ASM_ASSEMBLER_INLINE_HPP