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

Side by Side Diff: src/ia32/codegen-ia32.cc

Issue 23641009: Refactor and cleanup VirtualMemory. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed nits. 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 | « src/heap-inl.h ('k') | src/incremental-marking.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 masm->set_has_frame(false); 53 masm->set_has_frame(false);
54 } 54 }
55 55
56 56
57 #define __ masm. 57 #define __ masm.
58 58
59 59
60 UnaryMathFunction CreateTranscendentalFunction(TranscendentalCache::Type type) { 60 UnaryMathFunction CreateTranscendentalFunction(TranscendentalCache::Type type) {
61 size_t actual_size; 61 size_t actual_size;
62 // Allocate buffer in executable space. 62 // Allocate buffer in executable space.
63 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, 63 byte* buffer = static_cast<byte*>(VirtualMemory::AllocateRegion(
64 &actual_size, 64 1 * KB, &actual_size, VirtualMemory::EXECUTABLE));
65 true));
66 if (buffer == NULL) { 65 if (buffer == NULL) {
67 // Fallback to library function if function cannot be created. 66 // Fallback to library function if function cannot be created.
68 switch (type) { 67 switch (type) {
69 case TranscendentalCache::SIN: return &sin; 68 case TranscendentalCache::SIN: return &sin;
70 case TranscendentalCache::COS: return &cos; 69 case TranscendentalCache::COS: return &cos;
71 case TranscendentalCache::TAN: return &tan; 70 case TranscendentalCache::TAN: return &tan;
72 case TranscendentalCache::LOG: return &log; 71 case TranscendentalCache::LOG: return &log;
73 default: UNIMPLEMENTED(); 72 default: UNIMPLEMENTED();
74 } 73 }
75 } 74 }
(...skipping 14 matching lines...) Expand all
90 __ pop(edi); 89 __ pop(edi);
91 __ pop(edx); 90 __ pop(edx);
92 __ pop(ebx); 91 __ pop(ebx);
93 __ Ret(); 92 __ Ret();
94 93
95 CodeDesc desc; 94 CodeDesc desc;
96 masm.GetCode(&desc); 95 masm.GetCode(&desc);
97 ASSERT(!RelocInfo::RequiresRelocation(desc)); 96 ASSERT(!RelocInfo::RequiresRelocation(desc));
98 97
99 CPU::FlushICache(buffer, actual_size); 98 CPU::FlushICache(buffer, actual_size);
100 OS::ProtectCode(buffer, actual_size); 99 bool result = VirtualMemory::WriteProtectRegion(buffer, actual_size);
100 ASSERT(result);
101 USE(result);
101 return FUNCTION_CAST<UnaryMathFunction>(buffer); 102 return FUNCTION_CAST<UnaryMathFunction>(buffer);
102 } 103 }
103 104
104 105
105 UnaryMathFunction CreateExpFunction() { 106 UnaryMathFunction CreateExpFunction() {
106 if (!CpuFeatures::IsSupported(SSE2)) return &exp; 107 if (!CpuFeatures::IsSupported(SSE2)) return &exp;
107 if (!FLAG_fast_math) return &exp; 108 if (!FLAG_fast_math) return &exp;
108 size_t actual_size; 109 size_t actual_size;
109 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, &actual_size, true)); 110 byte* buffer = static_cast<byte*>(VirtualMemory::AllocateRegion(
111 1 * KB, &actual_size, VirtualMemory::EXECUTABLE));
110 if (buffer == NULL) return &exp; 112 if (buffer == NULL) return &exp;
111 ExternalReference::InitializeMathExpData(); 113 ExternalReference::InitializeMathExpData();
112 114
113 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); 115 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size));
114 // esp[1 * kPointerSize]: raw double input 116 // esp[1 * kPointerSize]: raw double input
115 // esp[0 * kPointerSize]: return address 117 // esp[0 * kPointerSize]: return address
116 { 118 {
117 CpuFeatureScope use_sse2(&masm, SSE2); 119 CpuFeatureScope use_sse2(&masm, SSE2);
118 XMMRegister input = xmm1; 120 XMMRegister input = xmm1;
119 XMMRegister result = xmm2; 121 XMMRegister result = xmm2;
120 __ movdbl(input, Operand(esp, 1 * kPointerSize)); 122 __ movdbl(input, Operand(esp, 1 * kPointerSize));
121 __ push(eax); 123 __ push(eax);
122 __ push(ebx); 124 __ push(ebx);
123 125
124 MathExpGenerator::EmitMathExp(&masm, input, result, xmm0, eax, ebx); 126 MathExpGenerator::EmitMathExp(&masm, input, result, xmm0, eax, ebx);
125 127
126 __ pop(ebx); 128 __ pop(ebx);
127 __ pop(eax); 129 __ pop(eax);
128 __ movdbl(Operand(esp, 1 * kPointerSize), result); 130 __ movdbl(Operand(esp, 1 * kPointerSize), result);
129 __ fld_d(Operand(esp, 1 * kPointerSize)); 131 __ fld_d(Operand(esp, 1 * kPointerSize));
130 __ Ret(); 132 __ Ret();
131 } 133 }
132 134
133 CodeDesc desc; 135 CodeDesc desc;
134 masm.GetCode(&desc); 136 masm.GetCode(&desc);
135 ASSERT(!RelocInfo::RequiresRelocation(desc)); 137 ASSERT(!RelocInfo::RequiresRelocation(desc));
136 138
137 CPU::FlushICache(buffer, actual_size); 139 CPU::FlushICache(buffer, actual_size);
138 OS::ProtectCode(buffer, actual_size); 140 bool result = VirtualMemory::WriteProtectRegion(buffer, actual_size);
141 ASSERT(result);
142 USE(result);
139 return FUNCTION_CAST<UnaryMathFunction>(buffer); 143 return FUNCTION_CAST<UnaryMathFunction>(buffer);
140 } 144 }
141 145
142 146
143 UnaryMathFunction CreateSqrtFunction() { 147 UnaryMathFunction CreateSqrtFunction() {
144 size_t actual_size; 148 size_t actual_size;
145 // Allocate buffer in executable space. 149 // Allocate buffer in executable space.
146 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, 150 byte* buffer = static_cast<byte*>(VirtualMemory::AllocateRegion(
147 &actual_size, 151 1 * KB, &actual_size, VirtualMemory::EXECUTABLE));
148 true));
149 // If SSE2 is not available, we can use libc's implementation to ensure 152 // If SSE2 is not available, we can use libc's implementation to ensure
150 // consistency since code by fullcodegen's calls into runtime in that case. 153 // consistency since code by fullcodegen's calls into runtime in that case.
151 if (buffer == NULL || !CpuFeatures::IsSupported(SSE2)) return &sqrt; 154 if (buffer == NULL || !CpuFeatures::IsSupported(SSE2)) return &sqrt;
152 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); 155 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size));
153 // esp[1 * kPointerSize]: raw double input 156 // esp[1 * kPointerSize]: raw double input
154 // esp[0 * kPointerSize]: return address 157 // esp[0 * kPointerSize]: return address
155 // Move double input into registers. 158 // Move double input into registers.
156 { 159 {
157 CpuFeatureScope use_sse2(&masm, SSE2); 160 CpuFeatureScope use_sse2(&masm, SSE2);
158 __ movdbl(xmm0, Operand(esp, 1 * kPointerSize)); 161 __ movdbl(xmm0, Operand(esp, 1 * kPointerSize));
159 __ sqrtsd(xmm0, xmm0); 162 __ sqrtsd(xmm0, xmm0);
160 __ movdbl(Operand(esp, 1 * kPointerSize), xmm0); 163 __ movdbl(Operand(esp, 1 * kPointerSize), xmm0);
161 // Load result into floating point register as return value. 164 // Load result into floating point register as return value.
162 __ fld_d(Operand(esp, 1 * kPointerSize)); 165 __ fld_d(Operand(esp, 1 * kPointerSize));
163 __ Ret(); 166 __ Ret();
164 } 167 }
165 168
166 CodeDesc desc; 169 CodeDesc desc;
167 masm.GetCode(&desc); 170 masm.GetCode(&desc);
168 ASSERT(!RelocInfo::RequiresRelocation(desc)); 171 ASSERT(!RelocInfo::RequiresRelocation(desc));
169 172
170 CPU::FlushICache(buffer, actual_size); 173 CPU::FlushICache(buffer, actual_size);
171 OS::ProtectCode(buffer, actual_size); 174 bool result = VirtualMemory::WriteProtectRegion(buffer, actual_size);
175 ASSERT(result);
176 USE(result);
172 return FUNCTION_CAST<UnaryMathFunction>(buffer); 177 return FUNCTION_CAST<UnaryMathFunction>(buffer);
173 } 178 }
174 179
175 180
176 // Helper functions for CreateMemMoveFunction. 181 // Helper functions for CreateMemMoveFunction.
177 #undef __ 182 #undef __
178 #define __ ACCESS_MASM(masm) 183 #define __ ACCESS_MASM(masm)
179 184
180 enum Direction { FORWARD, BACKWARD }; 185 enum Direction { FORWARD, BACKWARD };
181 enum Alignment { MOVE_ALIGNED, MOVE_UNALIGNED }; 186 enum Alignment { MOVE_ALIGNED, MOVE_UNALIGNED };
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 return reinterpret_cast<int32_t>(buffer_) + l->pos(); 260 return reinterpret_cast<int32_t>(buffer_) + l->pos();
256 } 261 }
257 private: 262 private:
258 byte* buffer_; 263 byte* buffer_;
259 }; 264 };
260 265
261 266
262 OS::MemMoveFunction CreateMemMoveFunction() { 267 OS::MemMoveFunction CreateMemMoveFunction() {
263 size_t actual_size; 268 size_t actual_size;
264 // Allocate buffer in executable space. 269 // Allocate buffer in executable space.
265 byte* buffer = static_cast<byte*>(OS::Allocate(1 * KB, &actual_size, true)); 270 byte* buffer = static_cast<byte*>(VirtualMemory::AllocateRegion(
271 1 * KB, &actual_size, VirtualMemory::EXECUTABLE));
266 if (buffer == NULL) return NULL; 272 if (buffer == NULL) return NULL;
267 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size)); 273 MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size));
268 LabelConverter conv(buffer); 274 LabelConverter conv(buffer);
269 275
270 // Generated code is put into a fixed, unmovable buffer, and not into 276 // Generated code is put into a fixed, unmovable buffer, and not into
271 // the V8 heap. We can't, and don't, refer to any relocatable addresses 277 // the V8 heap. We can't, and don't, refer to any relocatable addresses
272 // (e.g. the JavaScript nan-object). 278 // (e.g. the JavaScript nan-object).
273 279
274 // 32-bit C declaration function calls pass arguments on stack. 280 // 32-bit C declaration function calls pass arguments on stack.
275 281
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 } 638 }
633 } 639 }
634 640
635 __ bind(&pop_and_return); 641 __ bind(&pop_and_return);
636 MemMoveEmitPopAndReturn(&masm); 642 MemMoveEmitPopAndReturn(&masm);
637 643
638 CodeDesc desc; 644 CodeDesc desc;
639 masm.GetCode(&desc); 645 masm.GetCode(&desc);
640 ASSERT(!RelocInfo::RequiresRelocation(desc)); 646 ASSERT(!RelocInfo::RequiresRelocation(desc));
641 CPU::FlushICache(buffer, actual_size); 647 CPU::FlushICache(buffer, actual_size);
642 OS::ProtectCode(buffer, actual_size); 648 bool result = VirtualMemory::WriteProtectRegion(buffer, actual_size);
649 ASSERT(result);
650 USE(result);
643 // TODO(jkummerow): It would be nice to register this code creation event 651 // TODO(jkummerow): It would be nice to register this code creation event
644 // with the PROFILE / GDBJIT system. 652 // with the PROFILE / GDBJIT system.
645 return FUNCTION_CAST<OS::MemMoveFunction>(buffer); 653 return FUNCTION_CAST<OS::MemMoveFunction>(buffer);
646 } 654 }
647 655
648 656
649 #undef __ 657 #undef __
650 658
651 // ------------------------------------------------------------------------- 659 // -------------------------------------------------------------------------
652 // Code generators 660 // Code generators
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 Code* stub = GetCodeAgeStub(age, parity); 1185 Code* stub = GetCodeAgeStub(age, parity);
1178 CodePatcher patcher(sequence, young_length); 1186 CodePatcher patcher(sequence, young_length);
1179 patcher.masm()->call(stub->instruction_start(), RelocInfo::NONE32); 1187 patcher.masm()->call(stub->instruction_start(), RelocInfo::NONE32);
1180 } 1188 }
1181 } 1189 }
1182 1190
1183 1191
1184 } } // namespace v8::internal 1192 } } // namespace v8::internal
1185 1193
1186 #endif // V8_TARGET_ARCH_IA32 1194 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/heap-inl.h ('k') | src/incremental-marking.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698