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

Unified Diff: runtime/vm/code_patcher.cc

Issue 1192103004: VM: New calling convention for generated code. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fixed comments Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/code_patcher.h ('k') | runtime/vm/code_patcher_arm.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/code_patcher.cc
diff --git a/runtime/vm/code_patcher.cc b/runtime/vm/code_patcher.cc
index d57957727cbf49525a5cc560f0b0e3c9753bb513..c1fe9f74916b6d11a5a7c75d1325eca184017209 100644
--- a/runtime/vm/code_patcher.cc
+++ b/runtime/vm/code_patcher.cc
@@ -35,42 +35,11 @@ WritableInstructionsScope::~WritableInstructionsScope() {
}
-static void SwapCode(intptr_t num_bytes, char* code, char* buffer) {
- uword code_address = reinterpret_cast<uword>(code);
- for (intptr_t i = 0; i < num_bytes; i++) {
- char tmp = *code;
- *code = *buffer;
- *buffer = tmp;
- code++;
- buffer++;
- }
- CPU::FlushICache(code_address, num_bytes);
- // The buffer is not executed. No need to flush.
-}
-
-
// The patch code buffer contains the jmp code which will be inserted at
// entry point.
-void CodePatcher::PatchEntry(const Code& code) {
- ASSERT(!IsEntryPatched(code));
- const uword patch_addr = code.GetEntryPatchPc();
- ASSERT(patch_addr != 0);
- JumpPattern jmp_entry(patch_addr, code);
- ASSERT(!jmp_entry.IsValid());
- const uword patch_buffer = code.GetPatchCodePc();
- ASSERT(patch_buffer != 0);
- JumpPattern jmp_patch(patch_buffer, code);
- ASSERT(jmp_patch.IsValid());
- const uword jump_target = jmp_patch.TargetAddress();
- intptr_t length = jmp_patch.pattern_length_in_bytes();
- {
- WritableInstructionsScope writable_code(patch_addr, length);
- WritableInstructionsScope writable_buffer(patch_buffer, length);
- SwapCode(jmp_patch.pattern_length_in_bytes(),
- reinterpret_cast<char*>(patch_addr),
- reinterpret_cast<char*>(patch_buffer));
- jmp_entry.SetTargetAddress(jump_target);
- }
+void CodePatcher::PatchEntry(const Code& code, const Code& new_code) {
+ ASSERT(code.instructions() == code.active_instructions());
+ code.set_active_instructions(new_code.instructions());
}
@@ -78,59 +47,13 @@ void CodePatcher::PatchEntry(const Code& code) {
// original code, the entry point contains the jump instruction.
void CodePatcher::RestoreEntry(const Code& code) {
if (!IsEntryPatched(code)) return;
- const uword patch_addr = code.GetEntryPatchPc();
- ASSERT(patch_addr != 0);
- JumpPattern jmp_entry(patch_addr, code);
- ASSERT(jmp_entry.IsValid());
- const uword jump_target = jmp_entry.TargetAddress();
- const uword patch_buffer = code.GetPatchCodePc();
- ASSERT(patch_buffer != 0);
- // 'patch_buffer' contains original entry code.
- JumpPattern jmp_patch(patch_buffer, code);
- ASSERT(!jmp_patch.IsValid());
- intptr_t length = jmp_patch.pattern_length_in_bytes();
- {
- WritableInstructionsScope writable_code(patch_addr, length);
- WritableInstructionsScope writable_buffer(patch_buffer, length);
- SwapCode(jmp_patch.pattern_length_in_bytes(),
- reinterpret_cast<char*>(patch_addr),
- reinterpret_cast<char*>(patch_buffer));
- ASSERT(jmp_patch.IsValid());
- jmp_patch.SetTargetAddress(jump_target);
- }
+ ASSERT(code.instructions() != code.active_instructions());
+ code.set_active_instructions(code.instructions());
}
bool CodePatcher::IsEntryPatched(const Code& code) {
- const uword patch_addr = code.GetEntryPatchPc();
- if (patch_addr == 0) {
- return false;
- }
- JumpPattern jmp_entry(patch_addr, code);
- return jmp_entry.IsValid();
-}
-
-
-bool CodePatcher::CodeIsPatchable(const Code& code) {
- const uword patch_addr = code.GetEntryPatchPc();
- // Zero means means that the function is not patchable.
- if (patch_addr == 0) {
- return false;
- }
- JumpPattern jmp_entry(patch_addr, code);
- if (code.Size() < (jmp_entry.pattern_length_in_bytes() * 2)) {
- return false;
- }
- const uword limit = patch_addr + jmp_entry.pattern_length_in_bytes();
- // Check no object stored between patch_addr .. limit.
- for (intptr_t i = 0; i < code.pointer_offsets_length(); i++) {
- const uword obj_start = code.GetPointerOffsetAt(i) + code.EntryPoint();
- const uword obj_end = obj_start + kWordSize;
- if ((obj_start < limit) && (obj_end > patch_addr)) {
- return false;
- }
- }
- return true;
+ return code.instructions() != code.active_instructions();
}
} // namespace dart
« no previous file with comments | « runtime/vm/code_patcher.h ('k') | runtime/vm/code_patcher_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698