# HG changeset patch # User shade # Date 1439285066 -10800 # Tue Aug 11 12:24:26 2015 +0300 # Node ID 8309651c79a0ca6196f49f3133f57821ce1011dd # Parent 9edd3f7341f8d228f4e453117428b53319430a6e 8131682: C1 should use multibyte nops everywhere Reviewed-by: dlong, goetz, adinn, aph, vlivanov diff -r 9edd3f7341f8 -r 8309651c79a0 src/cpu/x86/vm/c1_CodeStubs_x86.cpp --- a/src/cpu/x86/vm/c1_CodeStubs_x86.cpp Thu Aug 06 13:00:44 2015 -0700 +++ b/src/cpu/x86/vm/c1_CodeStubs_x86.cpp Tue Aug 11 12:24:26 2015 +0300 @@ -416,7 +416,8 @@ int jmp_off = __ offset(); __ jmp(_patch_site_entry); // Add enough nops so deoptimization can overwrite the jmp above with a call - // and not destroy the world. + // and not destroy the world. We cannot use fat nops here, since the concurrent + // code rewrite may transiently create the illegal instruction sequence. for (int j = __ offset() ; j < jmp_off + 5 ; j++ ) { __ nop(); } diff -r 9edd3f7341f8 -r 8309651c79a0 src/cpu/x86/vm/c1_LIRAssembler_x86.cpp --- a/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp Thu Aug 06 13:00:44 2015 -0700 +++ b/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp Tue Aug 11 12:24:26 2015 +0300 @@ -345,9 +345,7 @@ const bool do_post_padding = VerifyOops || UseCompressedClassPointers; if (!do_post_padding) { // insert some nops so that the verified entry point is aligned on CodeEntryAlignment - while ((__ offset() + ic_cmp_size) % CodeEntryAlignment != 0) { - __ nop(); - } + __ align(CodeEntryAlignment, __ offset() + ic_cmp_size); } int offset = __ offset(); __ inline_cache_check(receiver, IC_Klass); @@ -2861,9 +2859,7 @@ case lir_virtual_call: // currently, sparc-specific for niagara default: ShouldNotReachHere(); } - while (offset++ % BytesPerWord != 0) { - __ nop(); - } + __ align(BytesPerWord, offset); } } @@ -2902,10 +2898,7 @@ int start = __ offset(); if (os::is_MP()) { // make sure that the displacement word of the call ends up word aligned - int offset = __ offset() + NativeMovConstReg::instruction_size + NativeCall::displacement_offset; - while (offset++ % BytesPerWord != 0) { - __ nop(); - } + __ align(BytesPerWord, __ offset() + NativeMovConstReg::instruction_size + NativeCall::displacement_offset); } __ relocate(static_stub_Relocation::spec(call_pc)); __ mov_metadata(rbx, (Metadata*)NULL); diff -r 9edd3f7341f8 -r 8309651c79a0 src/cpu/x86/vm/macroAssembler_x86.cpp --- a/src/cpu/x86/vm/macroAssembler_x86.cpp Thu Aug 06 13:00:44 2015 -0700 +++ b/src/cpu/x86/vm/macroAssembler_x86.cpp Tue Aug 11 12:24:26 2015 +0300 @@ -970,8 +970,12 @@ } void MacroAssembler::align(int modulus) { - if (offset() % modulus != 0) { - nop(modulus - (offset() % modulus)); + align(modulus, offset()); +} + +void MacroAssembler::align(int modulus, int target) { + if (target % modulus != 0) { + nop(modulus - (target % modulus)); } } diff -r 9edd3f7341f8 -r 8309651c79a0 src/cpu/x86/vm/macroAssembler_x86.hpp --- a/src/cpu/x86/vm/macroAssembler_x86.hpp Thu Aug 06 13:00:44 2015 -0700 +++ b/src/cpu/x86/vm/macroAssembler_x86.hpp Tue Aug 11 12:24:26 2015 +0300 @@ -192,6 +192,7 @@ // Alignment void align(int modulus); + void align(int modulus, int target); // A 5 byte nop that is safe for patching (see patch_verified_entry) void fat_nop(); diff -r 9edd3f7341f8 -r 8309651c79a0 src/share/vm/c1/c1_LIRAssembler.cpp --- a/src/share/vm/c1/c1_LIRAssembler.cpp Thu Aug 06 13:00:44 2015 -0700 +++ b/src/share/vm/c1/c1_LIRAssembler.cpp Tue Aug 11 12:24:26 2015 +0300 @@ -33,7 +33,9 @@ #include "runtime/os.hpp" void LIR_Assembler::patching_epilog(PatchingStub* patch, LIR_PatchCode patch_code, Register obj, CodeEmitInfo* info) { - // we must have enough patching space so that call can be inserted + // We must have enough patching space so that call can be inserted. + // We cannot use fat nops here, since the concurrent code rewrite may transiently + // create the illegal instruction sequence. while ((intx) _masm->pc() - (intx) patch->pc_start() < NativeCall::instruction_size) { _masm->nop(); } @@ -592,9 +594,7 @@ void LIR_Assembler::emit_op0(LIR_Op0* op) { switch (op->code()) { case lir_word_align: { - while (code_offset() % BytesPerWord != 0) { - _masm->nop(); - } + _masm->align(BytesPerWord); break; }