OLD | NEW |
1 // Copyright (c) 1994-2006 Sun Microsystems Inc. | 1 // Copyright (c) 1994-2006 Sun Microsystems Inc. |
2 // All Rights Reserved. | 2 // All Rights Reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // - Redistributions of source code must retain the above copyright notice, | 8 // - Redistributions of source code must retain the above copyright notice, |
9 // this list of conditions and the following disclaimer. | 9 // this list of conditions and the following disclaimer. |
10 // | 10 // |
(...skipping 24 matching lines...) Expand all Loading... |
35 #ifndef V8_ASSEMBLER_H_ | 35 #ifndef V8_ASSEMBLER_H_ |
36 #define V8_ASSEMBLER_H_ | 36 #define V8_ASSEMBLER_H_ |
37 | 37 |
38 #include "gdb-jit.h" | 38 #include "gdb-jit.h" |
39 #include "runtime.h" | 39 #include "runtime.h" |
40 #include "token.h" | 40 #include "token.h" |
41 | 41 |
42 namespace v8 { | 42 namespace v8 { |
43 namespace internal { | 43 namespace internal { |
44 | 44 |
45 const unsigned kNoASTId = -1; | 45 |
46 // ----------------------------------------------------------------------------- | 46 // ----------------------------------------------------------------------------- |
47 // Platform independent assembler base class. | 47 // Platform independent assembler base class. |
48 | 48 |
49 class AssemblerBase: public Malloced { | 49 class AssemblerBase: public Malloced { |
50 public: | 50 public: |
51 explicit AssemblerBase(Isolate* isolate) : isolate_(isolate) {} | 51 explicit AssemblerBase(Isolate* isolate) : isolate_(isolate) {} |
52 | 52 |
53 Isolate* isolate() const { return isolate_; } | 53 Isolate* isolate() const { return isolate_; } |
54 | 54 |
55 private: | 55 private: |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 static const int kMinRelocCommentSize = 3 + kPointerSize; | 202 static const int kMinRelocCommentSize = 3 + kPointerSize; |
203 | 203 |
204 // The maximum size for a call instruction including pc-jump. | 204 // The maximum size for a call instruction including pc-jump. |
205 static const int kMaxCallSize = 6; | 205 static const int kMaxCallSize = 6; |
206 | 206 |
207 // The maximum pc delta that will use the short encoding. | 207 // The maximum pc delta that will use the short encoding. |
208 static const int kMaxSmallPCDelta; | 208 static const int kMaxSmallPCDelta; |
209 | 209 |
210 enum Mode { | 210 enum Mode { |
211 // Please note the order is important (see IsCodeTarget, IsGCRelocMode). | 211 // Please note the order is important (see IsCodeTarget, IsGCRelocMode). |
212 CODE_TARGET, // Code target which is not any of the above. | |
213 CODE_TARGET_WITH_ID, | |
214 CONSTRUCT_CALL, // code target that is a call to a JavaScript constructor. | 212 CONSTRUCT_CALL, // code target that is a call to a JavaScript constructor. |
215 CODE_TARGET_CONTEXT, // Code target used for contextual loads and stores. | 213 CODE_TARGET_CONTEXT, // Code target used for contextual loads and stores. |
216 DEBUG_BREAK, // Code target for the debugger statement. | 214 DEBUG_BREAK, // Code target for the debugger statement. |
| 215 CODE_TARGET, // Code target which is not any of the above. |
217 EMBEDDED_OBJECT, | 216 EMBEDDED_OBJECT, |
218 GLOBAL_PROPERTY_CELL, | 217 GLOBAL_PROPERTY_CELL, |
219 | 218 |
220 // Everything after runtime_entry (inclusive) is not GC'ed. | 219 // Everything after runtime_entry (inclusive) is not GC'ed. |
221 RUNTIME_ENTRY, | 220 RUNTIME_ENTRY, |
222 JS_RETURN, // Marks start of the ExitJSFrame code. | 221 JS_RETURN, // Marks start of the ExitJSFrame code. |
223 COMMENT, | 222 COMMENT, |
224 POSITION, // See comment for kNoPosition above. | 223 POSITION, // See comment for kNoPosition above. |
225 STATEMENT_POSITION, // See comment for kNoPosition above. | 224 STATEMENT_POSITION, // See comment for kNoPosition above. |
226 DEBUG_BREAK_SLOT, // Additional code inserted for debug break slot. | 225 DEBUG_BREAK_SLOT, // Additional code inserted for debug break slot. |
227 EXTERNAL_REFERENCE, // The address of an external C++ function. | 226 EXTERNAL_REFERENCE, // The address of an external C++ function. |
228 INTERNAL_REFERENCE, // An address inside the same function. | 227 INTERNAL_REFERENCE, // An address inside the same function. |
229 | 228 |
230 // add more as needed | 229 // add more as needed |
231 // Pseudo-types | 230 // Pseudo-types |
232 NUMBER_OF_MODES, // There are at most 14 modes with noncompact encoding. | 231 NUMBER_OF_MODES, // must be no greater than 14 - see RelocInfoWriter |
233 NONE, // never recorded | 232 NONE, // never recorded |
234 LAST_CODE_ENUM = DEBUG_BREAK, | 233 LAST_CODE_ENUM = CODE_TARGET, |
235 LAST_GCED_ENUM = GLOBAL_PROPERTY_CELL, | 234 LAST_GCED_ENUM = GLOBAL_PROPERTY_CELL |
236 // Modes <= LAST_COMPACT_ENUM are guaranteed to have compact encoding. | |
237 LAST_COMPACT_ENUM = CODE_TARGET_WITH_ID | |
238 }; | 235 }; |
239 | 236 |
240 | 237 |
241 RelocInfo() {} | 238 RelocInfo() {} |
242 RelocInfo(byte* pc, Mode rmode, intptr_t data) | 239 RelocInfo(byte* pc, Mode rmode, intptr_t data) |
243 : pc_(pc), rmode_(rmode), data_(data) { | 240 : pc_(pc), rmode_(rmode), data_(data) { |
244 } | 241 } |
245 | 242 |
246 static inline bool IsConstructCall(Mode mode) { | 243 static inline bool IsConstructCall(Mode mode) { |
247 return mode == CONSTRUCT_CALL; | 244 return mode == CONSTRUCT_CALL; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 static const char* RelocModeName(Mode rmode); | 354 static const char* RelocModeName(Mode rmode); |
358 void Print(FILE* out); | 355 void Print(FILE* out); |
359 #endif // ENABLE_DISASSEMBLER | 356 #endif // ENABLE_DISASSEMBLER |
360 #ifdef DEBUG | 357 #ifdef DEBUG |
361 // Debugging | 358 // Debugging |
362 void Verify(); | 359 void Verify(); |
363 #endif | 360 #endif |
364 | 361 |
365 static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1; | 362 static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1; |
366 static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION; | 363 static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION; |
367 static const int kDataMask = | 364 static const int kDebugMask = kPositionMask | 1 << COMMENT; |
368 (1 << CODE_TARGET_WITH_ID) | kPositionMask | (1 << COMMENT); | |
369 static const int kApplyMask; // Modes affected by apply. Depends on arch. | 365 static const int kApplyMask; // Modes affected by apply. Depends on arch. |
370 | 366 |
371 private: | 367 private: |
372 // On ARM, note that pc_ is the address of the constant pool entry | 368 // On ARM, note that pc_ is the address of the constant pool entry |
373 // to be relocated and not the address of the instruction | 369 // to be relocated and not the address of the instruction |
374 // referencing the constant pool entry (except when rmode_ == | 370 // referencing the constant pool entry (except when rmode_ == |
375 // comment). | 371 // comment). |
376 byte* pc_; | 372 byte* pc_; |
377 Mode rmode_; | 373 Mode rmode_; |
378 intptr_t data_; | 374 intptr_t data_; |
379 friend class RelocIterator; | 375 friend class RelocIterator; |
380 }; | 376 }; |
381 | 377 |
382 | 378 |
383 // RelocInfoWriter serializes a stream of relocation info. It writes towards | 379 // RelocInfoWriter serializes a stream of relocation info. It writes towards |
384 // lower addresses. | 380 // lower addresses. |
385 class RelocInfoWriter BASE_EMBEDDED { | 381 class RelocInfoWriter BASE_EMBEDDED { |
386 public: | 382 public: |
387 RelocInfoWriter() : pos_(NULL), | 383 RelocInfoWriter() : pos_(NULL), last_pc_(NULL), last_data_(0) {} |
388 last_pc_(NULL), | 384 RelocInfoWriter(byte* pos, byte* pc) : pos_(pos), last_pc_(pc), |
389 last_id_(0), | 385 last_data_(0) {} |
390 last_position_(0) {} | |
391 RelocInfoWriter(byte* pos, byte* pc) : pos_(pos), | |
392 last_pc_(pc), | |
393 last_id_(0), | |
394 last_position_(0) {} | |
395 | 386 |
396 byte* pos() const { return pos_; } | 387 byte* pos() const { return pos_; } |
397 byte* last_pc() const { return last_pc_; } | 388 byte* last_pc() const { return last_pc_; } |
398 | 389 |
399 void Write(const RelocInfo* rinfo); | 390 void Write(const RelocInfo* rinfo); |
400 | 391 |
401 // Update the state of the stream after reloc info buffer | 392 // Update the state of the stream after reloc info buffer |
402 // and/or code is moved while the stream is active. | 393 // and/or code is moved while the stream is active. |
403 void Reposition(byte* pos, byte* pc) { | 394 void Reposition(byte* pos, byte* pc) { |
404 pos_ = pos; | 395 pos_ = pos; |
405 last_pc_ = pc; | 396 last_pc_ = pc; |
406 } | 397 } |
407 | 398 |
408 // Max size (bytes) of a written RelocInfo. Longest encoding is | 399 // Max size (bytes) of a written RelocInfo. Longest encoding is |
409 // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, ExtraTag, data_delta. | 400 // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, ExtraTag, data_delta. |
410 // On ia32 and arm this is 1 + 4 + 1 + 1 + 1 + 4 = 12. | 401 // On ia32 and arm this is 1 + 4 + 1 + 1 + 1 + 4 = 12. |
411 // On x64 this is 1 + 4 + 1 + 1 + 1 + 8 == 16; | 402 // On x64 this is 1 + 4 + 1 + 1 + 1 + 8 == 16; |
412 // Here we use the maximum of the two. | 403 // Here we use the maximum of the two. |
413 static const int kMaxSize = 16; | 404 static const int kMaxSize = 16; |
414 | 405 |
415 private: | 406 private: |
416 inline uint32_t WriteVariableLengthPCJump(uint32_t pc_delta); | 407 inline uint32_t WriteVariableLengthPCJump(uint32_t pc_delta); |
417 inline void WriteTaggedPC(uint32_t pc_delta, int tag); | 408 inline void WriteTaggedPC(uint32_t pc_delta, int tag); |
418 inline void WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag); | 409 inline void WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag); |
419 inline void WriteExtraTaggedIntData(int data_delta, int top_tag); | |
420 inline void WriteExtraTaggedData(intptr_t data_delta, int top_tag); | 410 inline void WriteExtraTaggedData(intptr_t data_delta, int top_tag); |
421 inline void WriteTaggedData(intptr_t data_delta, int tag); | 411 inline void WriteTaggedData(intptr_t data_delta, int tag); |
422 inline void WriteExtraTag(int extra_tag, int top_tag); | 412 inline void WriteExtraTag(int extra_tag, int top_tag); |
423 | 413 |
424 byte* pos_; | 414 byte* pos_; |
425 byte* last_pc_; | 415 byte* last_pc_; |
426 int last_id_; | 416 intptr_t last_data_; |
427 int last_position_; | |
428 DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter); | 417 DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter); |
429 }; | 418 }; |
430 | 419 |
431 | 420 |
432 // A RelocIterator iterates over relocation information. | 421 // A RelocIterator iterates over relocation information. |
433 // Typical use: | 422 // Typical use: |
434 // | 423 // |
435 // for (RelocIterator it(code); !it.done(); it.next()) { | 424 // for (RelocIterator it(code); !it.done(); it.next()) { |
436 // // do something with it.rinfo() here | 425 // // do something with it.rinfo() here |
437 // } | 426 // } |
(...skipping 21 matching lines...) Expand all Loading... |
459 private: | 448 private: |
460 // Advance* moves the position before/after reading. | 449 // Advance* moves the position before/after reading. |
461 // *Read* reads from current byte(s) into rinfo_. | 450 // *Read* reads from current byte(s) into rinfo_. |
462 // *Get* just reads and returns info on current byte. | 451 // *Get* just reads and returns info on current byte. |
463 void Advance(int bytes = 1) { pos_ -= bytes; } | 452 void Advance(int bytes = 1) { pos_ -= bytes; } |
464 int AdvanceGetTag(); | 453 int AdvanceGetTag(); |
465 int GetExtraTag(); | 454 int GetExtraTag(); |
466 int GetTopTag(); | 455 int GetTopTag(); |
467 void ReadTaggedPC(); | 456 void ReadTaggedPC(); |
468 void AdvanceReadPC(); | 457 void AdvanceReadPC(); |
469 void AdvanceReadId(); | |
470 void AdvanceReadPosition(); | |
471 void AdvanceReadData(); | 458 void AdvanceReadData(); |
472 void AdvanceReadVariableLengthPCJump(); | 459 void AdvanceReadVariableLengthPCJump(); |
473 int GetLocatableTypeTag(); | 460 int GetPositionTypeTag(); |
474 void ReadTaggedId(); | 461 void ReadTaggedData(); |
475 void ReadTaggedPosition(); | 462 |
| 463 static RelocInfo::Mode DebugInfoModeFromTag(int tag); |
476 | 464 |
477 // If the given mode is wanted, set it in rinfo_ and return true. | 465 // If the given mode is wanted, set it in rinfo_ and return true. |
478 // Else return false. Used for efficiently skipping unwanted modes. | 466 // Else return false. Used for efficiently skipping unwanted modes. |
479 bool SetMode(RelocInfo::Mode mode) { | 467 bool SetMode(RelocInfo::Mode mode) { |
480 return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode, true) : false; | 468 return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode, true) : false; |
481 } | 469 } |
482 | 470 |
483 byte* pos_; | 471 byte* pos_; |
484 byte* end_; | 472 byte* end_; |
485 RelocInfo rinfo_; | 473 RelocInfo rinfo_; |
486 bool done_; | 474 bool done_; |
487 int mode_mask_; | 475 int mode_mask_; |
488 int last_id_; | |
489 int last_position_; | |
490 DISALLOW_COPY_AND_ASSIGN(RelocIterator); | 476 DISALLOW_COPY_AND_ASSIGN(RelocIterator); |
491 }; | 477 }; |
492 | 478 |
493 | 479 |
494 //------------------------------------------------------------------------------ | 480 //------------------------------------------------------------------------------ |
495 // External function | 481 // External function |
496 | 482 |
497 //---------------------------------------------------------------------------- | 483 //---------------------------------------------------------------------------- |
498 class IC_Utility; | 484 class IC_Utility; |
499 class SCTableReference; | 485 class SCTableReference; |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 return num_bits_set; | 813 return num_bits_set; |
828 } | 814 } |
829 | 815 |
830 // Computes pow(x, y) with the special cases in the spec for Math.pow. | 816 // Computes pow(x, y) with the special cases in the spec for Math.pow. |
831 double power_double_int(double x, int y); | 817 double power_double_int(double x, int y); |
832 double power_double_double(double x, double y); | 818 double power_double_double(double x, double y); |
833 | 819 |
834 } } // namespace v8::internal | 820 } } // namespace v8::internal |
835 | 821 |
836 #endif // V8_ASSEMBLER_H_ | 822 #endif // V8_ASSEMBLER_H_ |
OLD | NEW |