MIPS: Serializer: serialize internal references via object visitor.
authorbalazs.kilvady <balazs.kilvady@imgtec.com>
Wed, 18 Mar 2015 21:41:30 +0000 (14:41 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 18 Mar 2015 21:41:36 +0000 (21:41 +0000)
Port 7c149afb6c875b1c53723384459dc14a0e961927

BUG=

Review URL: https://codereview.chromium.org/1019083002

Cr-Commit-Position: refs/heads/master@{#27283}

src/mips/assembler-mips-inl.h
src/mips/assembler-mips.h
src/mips64/assembler-mips64-inl.h
src/mips64/assembler-mips64.h

index ca6250e64e892eafd67c608534fcf5642a47af80..ce3d4767370a434407ee68d498b025359db068cd 100644 (file)
@@ -200,6 +200,28 @@ Address Assembler::break_address_from_return_address(Address pc) {
 }
 
 
+void Assembler::deserialization_set_target_internal_reference_at(
+    Address pc, Address target) {
+  if (IsLui(instr_at(pc))) {
+    // Encoded internal references are lui/ori load of 32-bit abolute address.
+    Instr instr_lui = Assembler::instr_at(pc + 0 * Assembler::kInstrSize);
+    Instr instr_ori = Assembler::instr_at(pc + 1 * Assembler::kInstrSize);
+    DCHECK(Assembler::IsLui(instr_lui));
+    DCHECK(Assembler::IsOri(instr_ori));
+    instr_lui &= ~kImm16Mask;
+    instr_ori &= ~kImm16Mask;
+    int32_t imm = reinterpret_cast<int32_t>(target);
+    DCHECK((imm & 3) == 0);
+    Assembler::instr_at_put(pc + 0 * Assembler::kInstrSize,
+                            instr_lui | ((imm >> kLuiShift) & kImm16Mask));
+    Assembler::instr_at_put(pc + 1 * Assembler::kInstrSize,
+                            instr_ori | (imm & kImm16Mask));
+  } else {
+    Memory::Address_at(pc) = target;
+  }
+}
+
+
 Object* RelocInfo::target_object() {
   DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
   return reinterpret_cast<Object*>(Assembler::target_address_at(pc_, host_));
@@ -239,6 +261,7 @@ Address RelocInfo::target_internal_reference() {
   if (rmode_ == INTERNAL_REFERENCE) {
     return Memory::Address_at(pc_);
   } else {
+    // Encoded internal references are lui/ori load of 32-bit abolute address.
     DCHECK(rmode_ == INTERNAL_REFERENCE_ENCODED);
     Instr instr_lui = Assembler::instr_at(pc_ + 0 * Assembler::kInstrSize);
     Instr instr_ori = Assembler::instr_at(pc_ + 1 * Assembler::kInstrSize);
@@ -251,27 +274,9 @@ Address RelocInfo::target_internal_reference() {
 }
 
 
-void RelocInfo::set_target_internal_reference(Address target) {
-  if (rmode_ == INTERNAL_REFERENCE) {
-    Memory::Address_at(pc_) = target;
-  } else {
-    // Encoded internal references are lui/ori load of 32-bit abolute address.
-    DCHECK(rmode_ == INTERNAL_REFERENCE_ENCODED);
-    Instr instr_lui = Assembler::instr_at(pc_ + 0 * Assembler::kInstrSize);
-    Instr instr_ori = Assembler::instr_at(pc_ + 1 * Assembler::kInstrSize);
-    DCHECK(Assembler::IsLui(instr_lui));
-    DCHECK(Assembler::IsOri(instr_ori));
-    instr_lui &= ~kImm16Mask;
-    instr_ori &= ~kImm16Mask;
-    int32_t imm = reinterpret_cast<int32_t>(target);
-    DCHECK((imm & 3) == 0);
-    Assembler::instr_at_put(pc_ + 0 * Assembler::kInstrSize,
-                            instr_lui | ((imm >> kLuiShift) & kImm16Mask));
-    Assembler::instr_at_put(pc_ + 1 * Assembler::kInstrSize,
-                            instr_ori | (imm & kImm16Mask));
-    // Currently used only by deserializer, and all code will be flushed
-    // after complete deserialization, no need to flush on each reference.
-  }
+Address RelocInfo::target_internal_reference_address() {
+  DCHECK(rmode_ == INTERNAL_REFERENCE || rmode_ == INTERNAL_REFERENCE_ENCODED);
+  return reinterpret_cast<Address>(pc_);
 }
 
 
@@ -386,11 +391,28 @@ void RelocInfo::set_call_object(Object* target) {
 
 
 void RelocInfo::WipeOut() {
-  DCHECK(IsEmbeddedObject(rmode_) ||
-         IsCodeTarget(rmode_) ||
-         IsRuntimeEntry(rmode_) ||
-         IsExternalReference(rmode_));
-  Assembler::set_target_address_at(pc_, host_, NULL);
+  DCHECK(IsEmbeddedObject(rmode_) || IsCodeTarget(rmode_) ||
+         IsRuntimeEntry(rmode_) || IsExternalReference(rmode_) ||
+         IsInternalReference(rmode_) || IsInternalReferenceEncoded(rmode_));
+  if (IsInternalReference(rmode_)) {
+    Memory::Address_at(pc_) = NULL;
+  } else if (IsInternalReferenceEncoded(rmode_)) {
+    Instr instr_lui = Assembler::instr_at(pc_ + 0 * Assembler::kInstrSize);
+    Instr instr_ori = Assembler::instr_at(pc_ + 1 * Assembler::kInstrSize);
+    DCHECK(Assembler::IsLui(instr_lui));
+    DCHECK(Assembler::IsOri(instr_ori));
+    instr_lui &= ~kImm16Mask;
+    instr_ori &= ~kImm16Mask;
+    int32_t imm = 0;
+    Assembler::instr_at_put(pc_ + 0 * Assembler::kInstrSize,
+                            instr_lui | ((imm >> kLuiShift) & kImm16Mask));
+    Assembler::instr_at_put(pc_ + 1 * Assembler::kInstrSize,
+                            instr_ori | (imm & kImm16Mask));
+    // Currently used only by deserializer, and all code will be flushed
+    // after complete deserialization, no need to flush on each reference.
+  } else {
+    Assembler::set_target_address_at(pc_, host_, NULL);
+  }
 }
 
 
@@ -423,6 +445,9 @@ void RelocInfo::Visit(Isolate* isolate, ObjectVisitor* visitor) {
     visitor->VisitCell(this);
   } else if (mode == RelocInfo::EXTERNAL_REFERENCE) {
     visitor->VisitExternalReference(this);
+  } else if (mode == RelocInfo::INTERNAL_REFERENCE ||
+             mode == RelocInfo::INTERNAL_REFERENCE_ENCODED) {
+    visitor->VisitInternalReference(this);
   } else if (RelocInfo::IsCodeAgeSequence(mode)) {
     visitor->VisitCodeAgeSequence(this);
   } else if (((RelocInfo::IsJSReturn(mode) &&
@@ -448,6 +473,9 @@ void RelocInfo::Visit(Heap* heap) {
     StaticVisitor::VisitCell(heap, this);
   } else if (mode == RelocInfo::EXTERNAL_REFERENCE) {
     StaticVisitor::VisitExternalReference(this);
+  } else if (mode == RelocInfo::INTERNAL_REFERENCE ||
+             mode == RelocInfo::INTERNAL_REFERENCE_ENCODED) {
+    StaticVisitor::VisitInternalReference(this);
   } else if (RelocInfo::IsCodeAgeSequence(mode)) {
     StaticVisitor::VisitCodeAgeSequence(heap, this);
   } else if (heap->isolate()->debug()->has_break_points() &&
index 8f2e9983d533f5b17729cc8249b64e54c1d6a8e3..a50927f7843930dd56dc5f87cf89983bc713ce33 100644 (file)
@@ -547,6 +547,10 @@ class Assembler : public AssemblerBase {
         target);
   }
 
+  // This sets the internal reference at the pc.
+  inline static void deserialization_set_target_internal_reference_at(
+      Address pc, Address target);
+
   // Size of an instruction.
   static const int kInstrSize = sizeof(Instr);
 
index e06c1c0f3f5e435fc4080d33d52faa5b3e6309b6..e8a27bcaad2a26304f3ce3c58140e78127b3d955 100644 (file)
@@ -194,6 +194,35 @@ Address Assembler::break_address_from_return_address(Address pc) {
 }
 
 
+void Assembler::deserialization_set_target_internal_reference_at(
+    Address pc, Address target) {
+  if (IsLui(instr_at(pc))) {
+    // Encoded internal references are lui/ori load of 48-bit abolute address.
+    Instr instr_lui = Assembler::instr_at(pc + 0 * Assembler::kInstrSize);
+    Instr instr_ori = Assembler::instr_at(pc + 1 * Assembler::kInstrSize);
+    Instr instr_ori2 = Assembler::instr_at(pc + 3 * Assembler::kInstrSize);
+    DCHECK(Assembler::IsLui(instr_lui));
+    DCHECK(Assembler::IsOri(instr_ori));
+    DCHECK(Assembler::IsOri(instr_ori2));
+    instr_lui &= ~kImm16Mask;
+    instr_ori &= ~kImm16Mask;
+    instr_ori2 &= ~kImm16Mask;
+    int64_t imm = reinterpret_cast<int64_t>(target);
+    DCHECK((imm & 3) == 0);
+    Assembler::instr_at_put(pc + 0 * Assembler::kInstrSize,
+                            instr_lui | ((imm >> 32) & kImm16Mask));
+    Assembler::instr_at_put(pc + 1 * Assembler::kInstrSize,
+                            instr_ori | ((imm >> 16) & kImm16Mask));
+    Assembler::instr_at_put(pc + 3 * Assembler::kInstrSize,
+                            instr_ori | (imm & kImm16Mask));
+    // Currently used only by deserializer, and all code will be flushed
+    // after complete deserialization, no need to flush on each reference.
+  } else {
+    Memory::Address_at(pc) = target;
+  }
+}
+
+
 Object* RelocInfo::target_object() {
   DCHECK(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
   return reinterpret_cast<Object*>(Assembler::target_address_at(pc_, host_));
@@ -233,6 +262,7 @@ Address RelocInfo::target_internal_reference() {
   if (rmode_ == INTERNAL_REFERENCE) {
     return Memory::Address_at(pc_);
   } else {
+    // Encoded internal references are lui/ori load of 48-bit abolute address.
     DCHECK(rmode_ == INTERNAL_REFERENCE_ENCODED);
     Instr instr_lui = Assembler::instr_at(pc_ + 0 * Assembler::kInstrSize);
     Instr instr_ori = Assembler::instr_at(pc_ + 1 * Assembler::kInstrSize);
@@ -248,32 +278,9 @@ Address RelocInfo::target_internal_reference() {
 }
 
 
-void RelocInfo::set_target_internal_reference(Address target) {
-  if (rmode_ == INTERNAL_REFERENCE) {
-    Memory::Address_at(pc_) = target;
-  } else {
-    // Encoded internal references are lui/ori load of 48-bit abolute address.
-    DCHECK(rmode_ == INTERNAL_REFERENCE_ENCODED);
-    Instr instr_lui = Assembler::instr_at(pc_ + 0 * Assembler::kInstrSize);
-    Instr instr_ori = Assembler::instr_at(pc_ + 1 * Assembler::kInstrSize);
-    Instr instr_ori2 = Assembler::instr_at(pc_ + 3 * Assembler::kInstrSize);
-    DCHECK(Assembler::IsLui(instr_lui));
-    DCHECK(Assembler::IsOri(instr_ori));
-    DCHECK(Assembler::IsOri(instr_ori2));
-    instr_lui &= ~kImm16Mask;
-    instr_ori &= ~kImm16Mask;
-    instr_ori2 &= ~kImm16Mask;
-    int64_t imm = reinterpret_cast<int64_t>(target);
-    DCHECK((imm & 3) == 0);
-    Assembler::instr_at_put(pc_ + 0 * Assembler::kInstrSize,
-                            instr_lui | ((imm >> 32) & kImm16Mask));
-    Assembler::instr_at_put(pc_ + 1 * Assembler::kInstrSize,
-                            instr_ori | ((imm >> 16) & kImm16Mask));
-    Assembler::instr_at_put(pc_ + 3 * Assembler::kInstrSize,
-                            instr_ori | (imm & kImm16Mask));
-    // Currently used only by deserializer, and all code will be flushed
-    // after complete deserialization, no need to flush on each reference.
-  }
+Address RelocInfo::target_internal_reference_address() {
+  DCHECK(rmode_ == INTERNAL_REFERENCE || rmode_ == INTERNAL_REFERENCE_ENCODED);
+  return reinterpret_cast<Address>(pc_);
 }
 
 
@@ -388,11 +395,33 @@ void RelocInfo::set_call_object(Object* target) {
 
 
 void RelocInfo::WipeOut() {
-  DCHECK(IsEmbeddedObject(rmode_) ||
-         IsCodeTarget(rmode_) ||
-         IsRuntimeEntry(rmode_) ||
-         IsExternalReference(rmode_));
-  Assembler::set_target_address_at(pc_, host_, NULL);
+  DCHECK(IsEmbeddedObject(rmode_) || IsCodeTarget(rmode_) ||
+         IsRuntimeEntry(rmode_) || IsExternalReference(rmode_) ||
+         IsInternalReference(rmode_) || IsInternalReferenceEncoded(rmode_));
+  if (IsInternalReference(rmode_)) {
+    Memory::Address_at(pc_) = NULL;
+  } else if (IsInternalReferenceEncoded(rmode_)) {
+    Instr instr_lui = Assembler::instr_at(pc_ + 0 * Assembler::kInstrSize);
+    Instr instr_ori = Assembler::instr_at(pc_ + 1 * Assembler::kInstrSize);
+    Instr instr_ori2 = Assembler::instr_at(pc_ + 3 * Assembler::kInstrSize);
+    DCHECK(Assembler::IsLui(instr_lui));
+    DCHECK(Assembler::IsOri(instr_ori));
+    DCHECK(Assembler::IsOri(instr_ori2));
+    instr_lui &= ~kImm16Mask;
+    instr_ori &= ~kImm16Mask;
+    instr_ori2 &= ~kImm16Mask;
+    int64_t imm = 0;
+    Assembler::instr_at_put(pc_ + 0 * Assembler::kInstrSize,
+                            instr_lui | ((imm >> 32) & kImm16Mask));
+    Assembler::instr_at_put(pc_ + 1 * Assembler::kInstrSize,
+                            instr_ori | ((imm >> 16) & kImm16Mask));
+    Assembler::instr_at_put(pc_ + 3 * Assembler::kInstrSize,
+                            instr_ori | (imm & kImm16Mask));
+    // Currently used only by deserializer, and all code will be flushed
+    // after complete deserialization, no need to flush on each reference.
+  } else {
+    Assembler::set_target_address_at(pc_, host_, NULL);
+  }
 }
 
 
@@ -428,6 +457,9 @@ void RelocInfo::Visit(Isolate* isolate, ObjectVisitor* visitor) {
     visitor->VisitCell(this);
   } else if (mode == RelocInfo::EXTERNAL_REFERENCE) {
     visitor->VisitExternalReference(this);
+  } else if (mode == RelocInfo::INTERNAL_REFERENCE ||
+             mode == RelocInfo::INTERNAL_REFERENCE_ENCODED) {
+    visitor->VisitInternalReference(this);
   } else if (RelocInfo::IsCodeAgeSequence(mode)) {
     visitor->VisitCodeAgeSequence(this);
   } else if (((RelocInfo::IsJSReturn(mode) &&
@@ -453,6 +485,9 @@ void RelocInfo::Visit(Heap* heap) {
     StaticVisitor::VisitCell(heap, this);
   } else if (mode == RelocInfo::EXTERNAL_REFERENCE) {
     StaticVisitor::VisitExternalReference(this);
+  } else if (mode == RelocInfo::INTERNAL_REFERENCE ||
+             mode == RelocInfo::INTERNAL_REFERENCE_ENCODED) {
+    StaticVisitor::VisitInternalReference(this);
   } else if (RelocInfo::IsCodeAgeSequence(mode)) {
     StaticVisitor::VisitCodeAgeSequence(heap, this);
   } else if (heap->isolate()->debug()->has_break_points() &&
index fbcf59a98245ea61d67205abb445093fd92746c9..f643322ddc62137a026b123dbfe545ad93f305ab 100644 (file)
@@ -540,6 +540,10 @@ class Assembler : public AssemblerBase {
         target);
   }
 
+  // This sets the internal reference at the pc.
+  inline static void deserialization_set_target_internal_reference_at(
+      Address pc, Address target);
+
   // Size of an instruction.
   static const int kInstrSize = sizeof(Instr);