199 class AbstractAssembler : public ResourceObj { |
199 class AbstractAssembler : public ResourceObj { |
200 friend class Label; |
200 friend class Label; |
201 |
201 |
202 protected: |
202 protected: |
203 CodeSection* _code_section; // section within the code buffer |
203 CodeSection* _code_section; // section within the code buffer |
204 address _code_begin; // first byte of code buffer |
|
205 address _code_limit; // first byte after code buffer |
|
206 address _code_pos; // current code generation position |
|
207 OopRecorder* _oop_recorder; // support for relocInfo::oop_type |
204 OopRecorder* _oop_recorder; // support for relocInfo::oop_type |
208 |
205 |
209 // Code emission & accessing |
206 // Code emission & accessing |
210 address addr_at(int pos) const { return _code_begin + pos; } |
207 inline address addr_at(int pos) const; |
211 |
208 |
212 // This routine is called with a label is used for an address. |
209 // This routine is called with a label is used for an address. |
213 // Labels and displacements truck in offsets, but target must return a PC. |
210 // Labels and displacements truck in offsets, but target must return a PC. |
214 address target(Label& L); // return _code_section->target(L) |
211 address target(Label& L); // return _code_section->target(L) |
215 |
212 |
216 bool is8bit(int x) const { return -0x80 <= x && x < 0x80; } |
213 bool is8bit(int x) const { return -0x80 <= x && x < 0x80; } |
217 bool isByte(int x) const { return 0 <= x && x < 0x100; } |
214 bool isByte(int x) const { return 0 <= x && x < 0x100; } |
218 bool isShiftCount(int x) const { return 0 <= x && x < 32; } |
215 bool isShiftCount(int x) const { return 0 <= x && x < 32; } |
219 |
216 |
220 void emit_byte(int x); // emit a single byte |
217 void emit_byte(int x) { emit_int8 (x); } // deprecated |
221 void emit_word(int x); // emit a 16-bit word (not a wordSize word!) |
218 void emit_word(int x) { emit_int16(x); } // deprecated |
222 void emit_long(jint x); // emit a 32-bit word (not a longSize word!) |
219 void emit_long(jint x) { emit_int32(x); } // deprecated |
223 void emit_address(address x); // emit an address (not a longSize word!) |
220 |
|
221 inline void emit_int8( int8_t x); |
|
222 inline void emit_int16( int16_t x); |
|
223 inline void emit_int32( int32_t x); |
|
224 inline void emit_int64( int64_t x); |
|
225 |
|
226 inline void emit_float( jfloat x); |
|
227 inline void emit_double(jdouble x); |
|
228 inline void emit_address(address x); |
224 |
229 |
225 // Instruction boundaries (required when emitting relocatable values). |
230 // Instruction boundaries (required when emitting relocatable values). |
226 class InstructionMark: public StackObj { |
231 class InstructionMark: public StackObj { |
227 private: |
232 private: |
228 AbstractAssembler* _assm; |
233 AbstractAssembler* _assm; |
306 static bool is_simm16(intptr_t x) { return is_simm(x, 16); } |
308 static bool is_simm16(intptr_t x) { return is_simm(x, 16); } |
307 static bool is_simm26(intptr_t x) { return is_simm(x, 26); } |
309 static bool is_simm26(intptr_t x) { return is_simm(x, 26); } |
308 static bool is_simm32(intptr_t x) { return is_simm(x, 32); } |
310 static bool is_simm32(intptr_t x) { return is_simm(x, 32); } |
309 |
311 |
310 // Accessors |
312 // Accessors |
311 CodeBuffer* code() const; // _code_section->outer() |
|
312 CodeSection* code_section() const { return _code_section; } |
313 CodeSection* code_section() const { return _code_section; } |
313 int sect() const; // return _code_section->index() |
314 inline CodeBuffer* code() const; |
314 address pc() const { return _code_pos; } |
315 inline int sect() const; |
315 int offset() const { return _code_pos - _code_begin; } |
316 inline address pc() const; |
316 int locator() const; // CodeBuffer::locator(offset(), sect()) |
317 inline int offset() const; |
|
318 inline int locator() const; // CodeBuffer::locator(offset(), sect()) |
|
319 |
317 OopRecorder* oop_recorder() const { return _oop_recorder; } |
320 OopRecorder* oop_recorder() const { return _oop_recorder; } |
318 void set_oop_recorder(OopRecorder* r) { _oop_recorder = r; } |
321 void set_oop_recorder(OopRecorder* r) { _oop_recorder = r; } |
319 |
322 |
320 address inst_mark() const; |
323 address inst_mark() const; |
321 void set_inst_mark(); |
324 void set_inst_mark(); |
356 // so we can reset to the proper section in end_a_const(). |
359 // so we can reset to the proper section in end_a_const(). |
357 address long_constant(jlong c) { |
360 address long_constant(jlong c) { |
358 CodeSection* c1 = _code_section; |
361 CodeSection* c1 = _code_section; |
359 address ptr = start_a_const(sizeof(c), sizeof(c)); |
362 address ptr = start_a_const(sizeof(c), sizeof(c)); |
360 if (ptr != NULL) { |
363 if (ptr != NULL) { |
361 *(jlong*)ptr = c; |
364 emit_int64(c); |
362 _code_pos = ptr + sizeof(c); |
|
363 end_a_const(c1); |
365 end_a_const(c1); |
364 } |
366 } |
365 return ptr; |
367 return ptr; |
366 } |
368 } |
367 address double_constant(jdouble c) { |
369 address double_constant(jdouble c) { |
368 CodeSection* c1 = _code_section; |
370 CodeSection* c1 = _code_section; |
369 address ptr = start_a_const(sizeof(c), sizeof(c)); |
371 address ptr = start_a_const(sizeof(c), sizeof(c)); |
370 if (ptr != NULL) { |
372 if (ptr != NULL) { |
371 *(jdouble*)ptr = c; |
373 emit_double(c); |
372 _code_pos = ptr + sizeof(c); |
|
373 end_a_const(c1); |
374 end_a_const(c1); |
374 } |
375 } |
375 return ptr; |
376 return ptr; |
376 } |
377 } |
377 address float_constant(jfloat c) { |
378 address float_constant(jfloat c) { |
378 CodeSection* c1 = _code_section; |
379 CodeSection* c1 = _code_section; |
379 address ptr = start_a_const(sizeof(c), sizeof(c)); |
380 address ptr = start_a_const(sizeof(c), sizeof(c)); |
380 if (ptr != NULL) { |
381 if (ptr != NULL) { |
381 *(jfloat*)ptr = c; |
382 emit_float(c); |
382 _code_pos = ptr + sizeof(c); |
|
383 end_a_const(c1); |
383 end_a_const(c1); |
384 } |
384 } |
385 return ptr; |
385 return ptr; |
386 } |
386 } |
387 address address_constant(address c) { |
387 address address_constant(address c) { |
388 CodeSection* c1 = _code_section; |
388 CodeSection* c1 = _code_section; |
389 address ptr = start_a_const(sizeof(c), sizeof(c)); |
389 address ptr = start_a_const(sizeof(c), sizeof(c)); |
390 if (ptr != NULL) { |
390 if (ptr != NULL) { |
391 *(address*)ptr = c; |
391 emit_address(c); |
392 _code_pos = ptr + sizeof(c); |
|
393 end_a_const(c1); |
392 end_a_const(c1); |
394 } |
393 } |
395 return ptr; |
394 return ptr; |
396 } |
395 } |
397 address address_constant(address c, RelocationHolder const& rspec) { |
396 address address_constant(address c, RelocationHolder const& rspec) { |
398 CodeSection* c1 = _code_section; |
397 CodeSection* c1 = _code_section; |
399 address ptr = start_a_const(sizeof(c), sizeof(c)); |
398 address ptr = start_a_const(sizeof(c), sizeof(c)); |
400 if (ptr != NULL) { |
399 if (ptr != NULL) { |
401 relocate(rspec); |
400 relocate(rspec); |
402 *(address*)ptr = c; |
401 emit_address(c); |
403 _code_pos = ptr + sizeof(c); |
|
404 end_a_const(c1); |
402 end_a_const(c1); |
405 } |
403 } |
406 return ptr; |
404 return ptr; |
407 } |
405 } |
408 |
406 |