Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(255)

Side by Side Diff: runtime/vm/instructions_x64.cc

Issue 22825023: Uses an object pool on x64 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/instructions_x64.h ('k') | runtime/vm/instructions_x64_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64.
6 #if defined(TARGET_ARCH_X64) 6 #if defined(TARGET_ARCH_X64)
7 7
8 #include "vm/cpu.h" 8 #include "vm/cpu.h"
9 #include "vm/instructions.h" 9 #include "vm/instructions.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 intptr_t InstructionPattern::IndexFromPPLoad(uword start) {
15 int32_t offset = *reinterpret_cast<int32_t*>(start);
16 offset += kHeapObjectTag;
17 return (offset - Array::data_offset()) / kWordSize;
18 }
19
20
14 bool InstructionPattern::TestBytesWith(const int* data, int num_bytes) const { 21 bool InstructionPattern::TestBytesWith(const int* data, int num_bytes) const {
15 ASSERT(data != NULL); 22 ASSERT(data != NULL);
16 const uint8_t* byte_array = reinterpret_cast<const uint8_t*>(start_); 23 const uint8_t* byte_array = reinterpret_cast<const uint8_t*>(start_);
17 for (int i = 0; i < num_bytes; i++) { 24 for (int i = 0; i < num_bytes; i++) {
18 // Skip comparison for data[i] < 0. 25 // Skip comparison for data[i] < 0.
19 if ((data[i] >= 0) && (byte_array[i] != (0xFF & data[i]))) { 26 if ((data[i] >= 0) && (byte_array[i] != (0xFF & data[i]))) {
20 return false; 27 return false;
21 } 28 }
22 } 29 }
23 return true; 30 return true;
24 } 31 }
25 32
26 33
27 uword CallOrJumpPattern::TargetAddress() const { 34 uword CallPattern::TargetAddress() const {
28 ASSERT(IsValid()); 35 ASSERT(IsValid());
29 return *reinterpret_cast<uword*>(start() + 2); 36 return *reinterpret_cast<uword*>(start() + 2);
30 } 37 }
31 38
32 39
33 void CallOrJumpPattern::SetTargetAddress(uword target) const { 40 void CallPattern::SetTargetAddress(uword target) const {
34 ASSERT(IsValid()); 41 ASSERT(IsValid());
35 *reinterpret_cast<uword*>(start() + 2) = target; 42 *reinterpret_cast<uword*>(start() + 2) = target;
36 CPU::FlushICache(start() + 2, kWordSize); 43 CPU::FlushICache(start() + 2, kWordSize);
37 } 44 }
38 45
39 46
40 const int* CallPattern::pattern() const { 47 const int* CallPattern::pattern() const {
41 // movq $target, TMP 48 // movq $target, TMP
42 // callq *TMP 49 // callq *TMP
43 static const int kCallPattern[kLengthInBytes] = 50 static const int kCallPattern[kLengthInBytes] =
44 {0x49, 0xBB, -1, -1, -1, -1, -1, -1, -1, -1, 0x41, 0xFF, 0xD3}; 51 {0x49, 0xBB, -1, -1, -1, -1, -1, -1, -1, -1, 0x41, 0xFF, 0xD3};
45 return kCallPattern; 52 return kCallPattern;
46 } 53 }
47 54
48 55
56 uword JumpPattern::TargetAddress() const {
57 ASSERT(IsValid());
58 int index = InstructionPattern::IndexFromPPLoad(start() + 3);
59 return reinterpret_cast<uword>(object_pool_.At(index));
60 }
61
62
63 void JumpPattern::SetTargetAddress(uword target) const {
64 ASSERT(IsValid());
65 int index = InstructionPattern::IndexFromPPLoad(start() + 3);
66 const Smi& smi = Smi::Handle(reinterpret_cast<RawSmi*>(target));
67 object_pool_.SetAt(index, smi);
68 // No need to flush the instruction cache, since the code is not modified.
69 }
70
71
49 const int* JumpPattern::pattern() const { 72 const int* JumpPattern::pattern() const {
50 // movq $target, TMP 73 // 00: 4d 8b 9d imm32 mov R11, [R13 + off]
51 // jmpq TMP 74 // 07: 41 ff e3 jmpq R11
52 static const int kJumpPattern[kLengthInBytes] = 75 static const int kJumpPattern[kLengthInBytes] =
53 {0x49, 0xBB, -1, -1, -1, -1, -1, -1, -1, -1, 0x41, 0xFF, 0xE3}; 76 {0x4D, 0x8B, -1, -1, -1, -1, -1, 0x41, 0xFF, 0xE3};
54 return kJumpPattern; 77 return kJumpPattern;
55 } 78 }
56 79
57 80
58 void ShortCallPattern::SetTargetAddress(uword target) const { 81 void ShortCallPattern::SetTargetAddress(uword target) const {
59 ASSERT(IsValid()); 82 ASSERT(IsValid());
60 *reinterpret_cast<uint32_t*>(start() + 1) = target - start() - kLengthInBytes; 83 *reinterpret_cast<uint32_t*>(start() + 1) = target - start() - kLengthInBytes;
61 CPU::FlushICache(start() + 1, kWordSize); 84 CPU::FlushICache(start() + 1, kWordSize);
62 } 85 }
63 86
64 87
65 const int* ShortCallPattern::pattern() const { 88 const int* ShortCallPattern::pattern() const {
66 static const int kCallPattern[kLengthInBytes] = {0xE8, -1, -1, -1, -1}; 89 static const int kCallPattern[kLengthInBytes] = {0xE8, -1, -1, -1, -1};
67 return kCallPattern; 90 return kCallPattern;
68 } 91 }
69 92
70 } // namespace dart 93 } // namespace dart
71 94
72 #endif // defined TARGET_ARCH_X64 95 #endif // defined TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « runtime/vm/instructions_x64.h ('k') | runtime/vm/instructions_x64_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698