| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 15 matching lines...) Expand all Loading... |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 | 29 |
| 30 #include "src/v8.h" | 30 #include "src/v8.h" |
| 31 #include "test/cctest/cctest.h" | 31 #include "test/cctest/cctest.h" |
| 32 | 32 |
| 33 #include "src/base/platform/platform.h" | 33 #include "src/base/platform/platform.h" |
| 34 #include "src/factory.h" | 34 #include "src/factory.h" |
| 35 #include "src/macro-assembler.h" | 35 #include "src/macro-assembler.h" |
| 36 #include "test/cctest/heap/heap-utils.h" |
| 36 | 37 |
| 37 using namespace v8::internal; | 38 using namespace v8::internal; |
| 38 | 39 |
| 39 #if __GNUC__ | 40 #if __GNUC__ |
| 40 #define STDCALL __attribute__((stdcall)) | 41 #define STDCALL __attribute__((stdcall)) |
| 41 #else | 42 #else |
| 42 #define STDCALL __stdcall | 43 #define STDCALL __stdcall |
| 43 #endif | 44 #endif |
| 44 | 45 |
| 45 typedef int STDCALL F0Type(); | 46 typedef int STDCALL F0Type(); |
| 47 typedef intptr_t STDCALL F1Type(); |
| 46 typedef F0Type* F0; | 48 typedef F0Type* F0; |
| 49 typedef F1Type* F1; |
| 47 | 50 |
| 48 #define __ masm-> | 51 #define __ masm-> |
| 49 | 52 |
| 50 | |
| 51 TEST(LoadAndStoreWithRepresentation) { | 53 TEST(LoadAndStoreWithRepresentation) { |
| 52 // Allocate an executable page of memory. | 54 // Allocate an executable page of memory. |
| 53 size_t actual_size; | 55 size_t actual_size; |
| 54 byte* buffer = static_cast<byte*>(v8::base::OS::Allocate( | 56 byte* buffer = static_cast<byte*>(v8::base::OS::Allocate( |
| 55 Assembler::kMinimalBufferSize, &actual_size, true)); | 57 Assembler::kMinimalBufferSize, &actual_size, true)); |
| 56 CHECK(buffer); | 58 CHECK(buffer); |
| 57 Isolate* isolate = CcTest::i_isolate(); | 59 Isolate* isolate = CcTest::i_isolate(); |
| 58 HandleScope handles(isolate); | 60 HandleScope handles(isolate); |
| 59 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size), | 61 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size), |
| 60 v8::internal::CodeObjectRequired::kYes); | 62 v8::internal::CodeObjectRequired::kYes); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 __ pop(ebx); | 153 __ pop(ebx); |
| 152 __ ret(0); | 154 __ ret(0); |
| 153 | 155 |
| 154 CodeDesc desc; | 156 CodeDesc desc; |
| 155 masm->GetCode(&desc); | 157 masm->GetCode(&desc); |
| 156 // Call the function from C++. | 158 // Call the function from C++. |
| 157 int result = FUNCTION_CAST<F0>(buffer)(); | 159 int result = FUNCTION_CAST<F0>(buffer)(); |
| 158 CHECK_EQ(0, result); | 160 CHECK_EQ(0, result); |
| 159 } | 161 } |
| 160 | 162 |
| 163 // Helper for the tests below. |
| 164 template <typename Fun> |
| 165 void AssembleFunction(Isolate* isolate, size_t actual_size, byte* buffer, |
| 166 Fun f) { |
| 167 MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size), |
| 168 v8::internal::CodeObjectRequired::kYes); |
| 169 MacroAssembler* masm = &assembler; |
| 170 Label exit; |
| 171 __ push(ebx); |
| 172 __ push(edx); |
| 173 __ sub(esp, Immediate(1 * kPointerSize)); |
| 174 f(masm); |
| 175 __ add(esp, Immediate(1 * kPointerSize)); |
| 176 __ pop(edx); |
| 177 __ pop(ebx); |
| 178 __ ret(0); |
| 179 |
| 180 CodeDesc desc; |
| 181 masm->GetCode(&desc); |
| 182 } |
| 183 |
| 184 TEST(AllocateMacrosNoGCRequired) { |
| 185 // Allocate an executable page of memory. |
| 186 size_t actual_size; |
| 187 byte* buffer = static_cast<byte*>(v8::base::OS::Allocate( |
| 188 Assembler::kMinimalBufferSize, &actual_size, true)); |
| 189 CHECK(buffer); |
| 190 Isolate* isolate = CcTest::i_isolate(); |
| 191 HandleScope handles(isolate); |
| 192 |
| 193 AllocationFlags const kDoubleAligned = |
| 194 static_cast<AllocationFlags>(DOUBLE_ALIGNMENT); |
| 195 AllocationFlags const kNoAllocationFlags = |
| 196 static_cast<AllocationFlags>(NO_ALLOCATION_FLAGS); |
| 197 |
| 198 #define CHECK_TAGGED(result) CHECK_EQ(result& kHeapObjectTag, 1); |
| 199 |
| 200 #define CHECK_DOUBLE_ALIGNED(result) \ |
| 201 do { \ |
| 202 CHECK_TAGGED((result)); \ |
| 203 CHECK_EQ((result)&kDoubleAlignmentMaskTagged, 0); \ |
| 204 /* Check that the filler was written in the correct place */ \ |
| 205 CHECK_EQ(*reinterpret_cast<v8::internal::Map***>( \ |
| 206 (result) - (kHeapObjectTag + kPointerSize)), \ |
| 207 isolate->factory()->one_pointer_filler_map().location()); \ |
| 208 } while (false) |
| 209 |
| 210 heap::GcAndSweep(isolate->heap(), AllocationSpace::NEW_SPACE); |
| 211 { |
| 212 AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) { |
| 213 Label gc_required, success; |
| 214 __ Allocate(kPointerSize, eax, ecx, edx, &gc_required, |
| 215 kNoAllocationFlags); |
| 216 __ jmp(&success); |
| 217 __ bind(&gc_required); |
| 218 __ Abort(kNoReason); |
| 219 __ bind(&success); |
| 220 }); |
| 221 intptr_t test_result = FUNCTION_CAST<F1>(buffer)(); |
| 222 CHECK_TAGGED(test_result); |
| 223 } |
| 224 |
| 225 { |
| 226 AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) { |
| 227 Label gc_required, success; |
| 228 __ Allocate(kDoubleSize, eax, ecx, edx, &gc_required, kDoubleAligned); |
| 229 __ jmp(&success); |
| 230 __ bind(&gc_required); |
| 231 __ Abort(kNoReason); |
| 232 __ bind(&success); |
| 233 }); |
| 234 heap::MakeSureNewSpaceTopIsNotDoubleAligned(isolate->heap()); |
| 235 intptr_t test_result = FUNCTION_CAST<F1>(buffer)(); |
| 236 CHECK_DOUBLE_ALIGNED(test_result); |
| 237 } |
| 238 { |
| 239 AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) { |
| 240 Label gc_required, success; |
| 241 __ mov(ebx, Immediate(kPointerSize)); |
| 242 __ Allocate(kPointerSize, eax, ecx, edx, &gc_required, |
| 243 kNoAllocationFlags); |
| 244 __ jmp(&success); |
| 245 __ bind(&gc_required); |
| 246 __ Abort(kNoReason); |
| 247 __ bind(&success); |
| 248 }); |
| 249 intptr_t test_result = FUNCTION_CAST<F1>(buffer)(); |
| 250 CHECK_TAGGED(test_result); |
| 251 } |
| 252 |
| 253 { |
| 254 AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) { |
| 255 Label gc_required, success; |
| 256 __ mov(ebx, Immediate(kDoubleSize)); |
| 257 __ Allocate(ebx, eax, ecx, edx, &gc_required, kDoubleAligned); |
| 258 __ jmp(&success); |
| 259 __ bind(&gc_required); |
| 260 __ Abort(kNoReason); |
| 261 __ bind(&success); |
| 262 }); |
| 263 heap::MakeSureNewSpaceTopIsNotDoubleAligned(isolate->heap()); |
| 264 intptr_t test_result = FUNCTION_CAST<F1>(buffer)(); |
| 265 CHECK_DOUBLE_ALIGNED(test_result); |
| 266 } |
| 267 |
| 268 { |
| 269 AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) { |
| 270 Label gc_required, success; |
| 271 __ mov(ebx, Immediate(2)); |
| 272 __ Allocate(0, times_4, ebx, REGISTER_VALUE_IS_SMI, eax, ecx, edx, |
| 273 &gc_required, kNoAllocationFlags); |
| 274 __ jmp(&success); |
| 275 __ bind(&gc_required); |
| 276 __ Abort(kNoReason); |
| 277 __ bind(&success); |
| 278 }); |
| 279 intptr_t test_result = FUNCTION_CAST<F1>(buffer)(); |
| 280 CHECK_TAGGED(test_result); |
| 281 } |
| 282 |
| 283 { |
| 284 AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) { |
| 285 Label gc_required, success; |
| 286 __ mov(ebx, Immediate(kDoubleSize)); |
| 287 __ Allocate(FixedDoubleArray::kHeaderSize, times_8, ebx, |
| 288 REGISTER_VALUE_IS_SMI, eax, ecx, edx, &gc_required, |
| 289 kDoubleAligned); |
| 290 __ jmp(&success); |
| 291 __ bind(&gc_required); |
| 292 __ Abort(kNoReason); |
| 293 __ bind(&success); |
| 294 }); |
| 295 heap::MakeSureNewSpaceTopIsNotDoubleAligned(isolate->heap()); |
| 296 intptr_t test_result = FUNCTION_CAST<F1>(buffer)(); |
| 297 CHECK_DOUBLE_ALIGNED(test_result); |
| 298 } |
| 299 #undef CHECK_TAGGED |
| 300 #undef CHECK_DOUBLE_ALIGNED |
| 301 } |
| 302 |
| 303 TEST(AllocateMacrosGCRequired) { |
| 304 // Allocate an executable page of memory. |
| 305 size_t actual_size; |
| 306 byte* buffer = static_cast<byte*>(v8::base::OS::Allocate( |
| 307 Assembler::kMinimalBufferSize, &actual_size, true)); |
| 308 CHECK(buffer); |
| 309 Isolate* isolate = CcTest::i_isolate(); |
| 310 HandleScope handles(isolate); |
| 311 |
| 312 AllocationFlags const kDoubleAligned = |
| 313 static_cast<AllocationFlags>(DOUBLE_ALIGNMENT); |
| 314 |
| 315 // Test that the macro jumps to the gc_required label if there's not enough |
| 316 // space to allocate with double alignment. |
| 317 { |
| 318 AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) { |
| 319 Label gc_required, end; |
| 320 __ Allocate(kPointerSize, eax, ecx, edx, &gc_required, kDoubleAligned); |
| 321 __ xor_(eax, eax); |
| 322 __ jmp(&end); |
| 323 __ bind(&gc_required); |
| 324 __ mov(eax, Immediate(1)); |
| 325 __ bind(&end); |
| 326 }); |
| 327 heap::AllocateAllButNBytes(isolate->heap()->new_space(), 4); |
| 328 intptr_t test_result = FUNCTION_CAST<F1>(buffer)(); |
| 329 CHECK_EQ(test_result, 1); |
| 330 } |
| 331 |
| 332 { |
| 333 AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) { |
| 334 Label gc_required, end; |
| 335 __ mov(ebx, Immediate(kPointerSize)); |
| 336 __ Allocate(ebx, eax, ecx, edx, &gc_required, kDoubleAligned); |
| 337 __ xor_(eax, eax); |
| 338 __ jmp(&end); |
| 339 __ bind(&gc_required); |
| 340 __ mov(eax, Immediate(1)); |
| 341 __ bind(&end); |
| 342 }); |
| 343 heap::AllocateAllButNBytes(isolate->heap()->new_space(), 4); |
| 344 intptr_t test_result = FUNCTION_CAST<F1>(buffer)(); |
| 345 CHECK_EQ(test_result, 1); |
| 346 } |
| 347 |
| 348 { |
| 349 AssembleFunction(isolate, actual_size, buffer, [](MacroAssembler* masm) { |
| 350 Label gc_required, end; |
| 351 __ mov(ebx, Immediate(kPointerSize)); |
| 352 __ Allocate(0, times_8, ebx, REGISTER_VALUE_IS_SMI, eax, ecx, edx, |
| 353 &gc_required, kDoubleAligned); |
| 354 __ xor_(eax, eax); |
| 355 __ jmp(&end); |
| 356 __ bind(&gc_required); |
| 357 __ mov(eax, Immediate(1)); |
| 358 __ bind(&end); |
| 359 }); |
| 360 heap::AllocateAllButNBytes(isolate->heap()->new_space(), 4); |
| 361 intptr_t test_result = FUNCTION_CAST<F1>(buffer)(); |
| 362 CHECK_EQ(test_result, 1); |
| 363 } |
| 364 } |
| 365 |
| 161 #undef __ | 366 #undef __ |
| OLD | NEW |