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

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

Issue 677193002: - Use the simulator to do atomic operations that could also (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 1 month 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/simulator_arm64.h ('k') | runtime/vm/simulator_mips.h » ('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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 <setjmp.h> 5 #include <setjmp.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 7
8 #include "vm/globals.h" 8 #include "vm/globals.h"
9 #if defined(TARGET_ARCH_ARM64) 9 #if defined(TARGET_ARCH_ARM64)
10 10
11 // Only build the simulator if not compiling for real ARM hardware. 11 // Only build the simulator if not compiling for real ARM hardware.
12 #if !defined(HOST_ARCH_ARM64) 12 #if !defined(HOST_ARCH_ARM64)
13 13
14 #include "vm/simulator.h" 14 #include "vm/simulator.h"
15 15
16 #include "vm/assembler.h" 16 #include "vm/assembler.h"
17 #include "vm/constants_arm64.h" 17 #include "vm/constants_arm64.h"
18 #include "vm/cpu.h" 18 #include "vm/cpu.h"
19 #include "vm/disassembler.h" 19 #include "vm/disassembler.h"
20 #include "vm/lockers.h"
20 #include "vm/native_arguments.h" 21 #include "vm/native_arguments.h"
21 #include "vm/stack_frame.h" 22 #include "vm/stack_frame.h"
22 #include "vm/thread.h" 23 #include "vm/thread.h"
23 24
24 namespace dart { 25 namespace dart {
25 26
26 DEFINE_FLAG(bool, trace_sim, false, "Trace simulator execution."); 27 DEFINE_FLAG(bool, trace_sim, false, "Trace simulator execution.");
27 DEFINE_FLAG(int, stop_sim_at, 0, "Address to stop simulator at."); 28 DEFINE_FLAG(int, stop_sim_at, 0, "Address to stop simulator at.");
28 29
29 30
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 // Copy the newly read line into the result. 523 // Copy the newly read line into the result.
523 memmove(result + offset, line_buf, len); 524 memmove(result + offset, line_buf, len);
524 offset += len; 525 offset += len;
525 } 526 }
526 ASSERT(result != NULL); 527 ASSERT(result != NULL);
527 result[offset] = '\0'; 528 result[offset] = '\0';
528 return result; 529 return result;
529 } 530 }
530 531
531 532
533 // Synchronization primitives support.
534 Mutex* Simulator::exclusive_access_lock_ = NULL;
535 Simulator::AddressTag Simulator::exclusive_access_state_[kNumAddressTags] =
536 {{NULL, 0}};
537 int Simulator::next_address_tag_ = 0;
538
539
540 void Simulator::InitOnce() {
541 // Setup exclusive access state lock.
542 exclusive_access_lock_ = new Mutex();
543 }
544
545
532 Simulator::Simulator() { 546 Simulator::Simulator() {
533 // Setup simulator support first. Some of this information is needed to 547 // Setup simulator support first. Some of this information is needed to
534 // setup the architecture state. 548 // setup the architecture state.
535 // We allocate the stack here, the size is computed as the sum of 549 // We allocate the stack here, the size is computed as the sum of
536 // the size specified by the user and the buffer space needed for 550 // the size specified by the user and the buffer space needed for
537 // handling stack overflow exceptions. To be safe in potential 551 // handling stack overflow exceptions. To be safe in potential
538 // stack underflows we also add some underflow buffer space. 552 // stack underflows we also add some underflow buffer space.
539 stack_ = new char[(Isolate::GetSpecifiedStackSize() + 553 stack_ = new char[(Isolate::GetSpecifiedStackSize() +
540 Isolate::kStackSizeBuffer + 554 Isolate::kStackSizeBuffer +
541 kSimulatorStackUnderflowSize)]; 555 kSimulatorStackUnderflowSize)];
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 return *ptr; 930 return *ptr;
917 } 931 }
918 932
919 933
920 void Simulator::WriteB(uword addr, uint8_t value) { 934 void Simulator::WriteB(uword addr, uint8_t value) {
921 uint8_t* ptr = reinterpret_cast<uint8_t*>(addr); 935 uint8_t* ptr = reinterpret_cast<uint8_t*>(addr);
922 *ptr = value; 936 *ptr = value;
923 } 937 }
924 938
925 939
940 // Synchronization primitives support.
941 void Simulator::SetExclusiveAccess(uword addr) {
942 Isolate* isolate = Isolate::Current();
943 ASSERT(isolate != NULL);
944 ASSERT(exclusive_access_lock_->Owner() == isolate);
945 int i = 0;
946 // Find an entry for this isolate in the exclusive access state.
947 while ((i < kNumAddressTags) &&
948 (exclusive_access_state_[i].isolate != isolate)) {
949 i++;
950 }
951 // Round-robin replacement of previously used entries.
952 if (i == kNumAddressTags) {
953 i = next_address_tag_;
954 if (++next_address_tag_ == kNumAddressTags) {
955 next_address_tag_ = 0;
956 }
957 exclusive_access_state_[i].isolate = isolate;
958 }
959 // Remember the address being reserved.
960 exclusive_access_state_[i].addr = addr;
961 }
962
963
964 bool Simulator::HasExclusiveAccessAndOpen(uword addr) {
965 Isolate* isolate = Isolate::Current();
966 ASSERT(isolate != NULL);
967 ASSERT(addr != 0);
968 ASSERT(exclusive_access_lock_->Owner() == isolate);
969 bool result = false;
970 for (int i = 0; i < kNumAddressTags; i++) {
971 if (exclusive_access_state_[i].isolate == isolate) {
972 // Check whether the current isolates address reservation matches.
973 if (exclusive_access_state_[i].addr == addr) {
974 result = true;
975 }
976 exclusive_access_state_[i].addr = 0;
977 } else if (exclusive_access_state_[i].addr == addr) {
978 // Other isolates with matching address lose their reservations.
979 exclusive_access_state_[i].addr = 0;
980 }
981 }
982 return result;
983 }
984
985
986 void Simulator::ClearExclusive() {
987 MutexLocker ml(exclusive_access_lock_);
988 // Remove the reservation for this isolate.
989 SetExclusiveAccess(NULL);
990 }
991
992
993 intptr_t Simulator::ReadExclusiveW(uword addr, Instr* instr) {
994 MutexLocker ml(exclusive_access_lock_);
995 SetExclusiveAccess(addr);
996 return ReadW(addr, instr);
997 }
998
999
1000 intptr_t Simulator::WriteExclusiveW(uword addr, intptr_t value, Instr* instr) {
1001 MutexLocker ml(exclusive_access_lock_);
1002 bool write_allowed = HasExclusiveAccessAndOpen(addr);
1003 if (write_allowed) {
1004 WriteW(addr, value, instr);
1005 return 0; // Success.
1006 }
1007 return 1; // Failure.
1008 }
1009
1010
1011 uword Simulator::CompareExchange(uword* address,
1012 uword compare_value,
1013 uword new_value) {
1014 MutexLocker ml(exclusive_access_lock_);
1015 // We do not get a reservation as it would be guaranteed to be found when
1016 // writing below. No other isolate is able to make a reservation while we
1017 // hold the lock.
1018 uword value = *address;
1019 if (value == compare_value) {
1020 *address = new_value;
1021 // Same effect on exclusive access state as a successful STREX.
1022 HasExclusiveAccessAndOpen(reinterpret_cast<uword>(address));
1023 } else {
1024 // Same effect on exclusive access state as an LDREX.
1025 SetExclusiveAccess(reinterpret_cast<uword>(address));
1026 }
1027 return value;
1028 }
1029
1030
926 // Unsupported instructions use Format to print an error and stop execution. 1031 // Unsupported instructions use Format to print an error and stop execution.
927 void Simulator::Format(Instr* instr, const char* format) { 1032 void Simulator::Format(Instr* instr, const char* format) {
928 OS::Print("Simulator found unsupported instruction:\n 0x%p: %s\n", 1033 OS::Print("Simulator found unsupported instruction:\n 0x%p: %s\n",
929 instr, 1034 instr,
930 format); 1035 format);
931 UNIMPLEMENTED(); 1036 UNIMPLEMENTED();
932 } 1037 }
933 1038
934 1039
935 // Calculate and set the Negative and Zero flags. 1040 // Calculate and set the Negative and Zero flags.
(...skipping 2205 matching lines...) Expand 10 before | Expand all | Expand 10 after
3141 set_register(NULL, kExceptionObjectReg, bit_cast<int64_t>(raw_exception)); 3246 set_register(NULL, kExceptionObjectReg, bit_cast<int64_t>(raw_exception));
3142 set_register(NULL, kStackTraceObjectReg, bit_cast<int64_t>(raw_stacktrace)); 3247 set_register(NULL, kStackTraceObjectReg, bit_cast<int64_t>(raw_stacktrace));
3143 buf->Longjmp(); 3248 buf->Longjmp();
3144 } 3249 }
3145 3250
3146 } // namespace dart 3251 } // namespace dart
3147 3252
3148 #endif // !defined(HOST_ARCH_ARM64) 3253 #endif // !defined(HOST_ARCH_ARM64)
3149 3254
3150 #endif // defined TARGET_ARCH_ARM64 3255 #endif // defined TARGET_ARCH_ARM64
OLDNEW
« no previous file with comments | « runtime/vm/simulator_arm64.h ('k') | runtime/vm/simulator_mips.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698