src/cpu/x86/vm/x86_32.ad

changeset 3574
fd8114661503
parent 3406
e9a5e0a812c8
child 3577
9b8ce46870df
     1.1 --- a/src/cpu/x86/vm/x86_32.ad	Wed Feb 15 16:29:40 2012 -0800
     1.2 +++ b/src/cpu/x86/vm/x86_32.ad	Wed Feb 15 21:37:49 2012 -0800
     1.3 @@ -550,118 +550,66 @@
     1.4  
     1.5  //=============================================================================
     1.6  #ifndef PRODUCT
     1.7 -void MachPrologNode::format( PhaseRegAlloc *ra_, outputStream* st ) const {
     1.8 +void MachPrologNode::format(PhaseRegAlloc* ra_, outputStream* st) const {
     1.9    Compile* C = ra_->C;
    1.10 -  if( C->in_24_bit_fp_mode() ) {
    1.11 -    st->print("FLDCW  24 bit fpu control word");
    1.12 -    st->print_cr(""); st->print("\t");
    1.13 -  }
    1.14  
    1.15    int framesize = C->frame_slots() << LogBytesPerInt;
    1.16    assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
    1.17 -  // Remove two words for return addr and rbp,
    1.18 -  framesize -= 2*wordSize;
    1.19 -
    1.20 -  // Calls to C2R adapters often do not accept exceptional returns.
    1.21 -  // We require that their callers must bang for them.  But be careful, because
    1.22 -  // some VM calls (such as call site linkage) can use several kilobytes of
    1.23 -  // stack.  But the stack safety zone should account for that.
    1.24 -  // See bugs 4446381, 4468289, 4497237.
    1.25 +  // Remove wordSize for return addr which is already pushed.
    1.26 +  framesize -= wordSize;
    1.27 +
    1.28    if (C->need_stack_bang(framesize)) {
    1.29 -    st->print_cr("# stack bang"); st->print("\t");
    1.30 -  }
    1.31 -  st->print_cr("PUSHL  EBP"); st->print("\t");
    1.32 -
    1.33 -  if( VerifyStackAtCalls ) { // Majik cookie to verify stack depth
    1.34 -    st->print("PUSH   0xBADB100D\t# Majik cookie for stack depth check");
    1.35 -    st->print_cr(""); st->print("\t");
    1.36      framesize -= wordSize;
    1.37 -  }
    1.38 -
    1.39 -  if ((C->in_24_bit_fp_mode() || VerifyStackAtCalls ) && framesize < 128 ) {
    1.40 +    st->print("# stack bang");
    1.41 +    st->print("\n\t");
    1.42 +    st->print("PUSH   EBP\t# Save EBP");
    1.43      if (framesize) {
    1.44 -      st->print("SUB    ESP,%d\t# Create frame",framesize);
    1.45 +      st->print("\n\t");
    1.46 +      st->print("SUB    ESP, #%d\t# Create frame",framesize);
    1.47      }
    1.48    } else {
    1.49 -    st->print("SUB    ESP,%d\t# Create frame",framesize);
    1.50 +    st->print("SUB    ESP, #%d\t# Create frame",framesize);
    1.51 +    st->print("\n\t");
    1.52 +    framesize -= wordSize;
    1.53 +    st->print("MOV    [ESP + #%d], EBP\t# Save EBP",framesize);
    1.54    }
    1.55 +
    1.56 +  if (VerifyStackAtCalls) {
    1.57 +    st->print("\n\t");
    1.58 +    framesize -= wordSize;
    1.59 +    st->print("MOV    [ESP + #%d], 0xBADB100D\t# Majik cookie for stack depth check",framesize);
    1.60 +  }
    1.61 +
    1.62 +  if( C->in_24_bit_fp_mode() ) {
    1.63 +    st->print("\n\t");
    1.64 +    st->print("FLDCW  \t# load 24 bit fpu control word");
    1.65 +  }
    1.66 +  if (UseSSE >= 2 && VerifyFPU) {
    1.67 +    st->print("\n\t");
    1.68 +    st->print("# verify FPU stack (must be clean on entry)");
    1.69 +  }
    1.70 +
    1.71 +#ifdef ASSERT
    1.72 +  if (VerifyStackAtCalls) {
    1.73 +    st->print("\n\t");
    1.74 +    st->print("# stack alignment check");
    1.75 +  }
    1.76 +#endif
    1.77 +  st->cr();
    1.78  }
    1.79  #endif
    1.80  
    1.81  
    1.82  void MachPrologNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {
    1.83    Compile* C = ra_->C;
    1.84 -
    1.85 -  if (UseSSE >= 2 && VerifyFPU) {
    1.86 -    MacroAssembler masm(&cbuf);
    1.87 -    masm.verify_FPU(0, "FPU stack must be clean on entry");
    1.88 -  }
    1.89 -
    1.90 -  // WARNING: Initial instruction MUST be 5 bytes or longer so that
    1.91 -  // NativeJump::patch_verified_entry will be able to patch out the entry
    1.92 -  // code safely. The fldcw is ok at 6 bytes, the push to verify stack
    1.93 -  // depth is ok at 5 bytes, the frame allocation can be either 3 or
    1.94 -  // 6 bytes. So if we don't do the fldcw or the push then we must
    1.95 -  // use the 6 byte frame allocation even if we have no frame. :-(
    1.96 -  // If method sets FPU control word do it now
    1.97 -  if( C->in_24_bit_fp_mode() ) {
    1.98 -    MacroAssembler masm(&cbuf);
    1.99 -    masm.fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_24()));
   1.100 -  }
   1.101 +  MacroAssembler _masm(&cbuf);
   1.102  
   1.103    int framesize = C->frame_slots() << LogBytesPerInt;
   1.104 -  assert((framesize & (StackAlignmentInBytes-1)) == 0, "frame size not aligned");
   1.105 -  // Remove two words for return addr and rbp,
   1.106 -  framesize -= 2*wordSize;
   1.107 -
   1.108 -  // Calls to C2R adapters often do not accept exceptional returns.
   1.109 -  // We require that their callers must bang for them.  But be careful, because
   1.110 -  // some VM calls (such as call site linkage) can use several kilobytes of
   1.111 -  // stack.  But the stack safety zone should account for that.
   1.112 -  // See bugs 4446381, 4468289, 4497237.
   1.113 -  if (C->need_stack_bang(framesize)) {
   1.114 -    MacroAssembler masm(&cbuf);
   1.115 -    masm.generate_stack_overflow_check(framesize);
   1.116 -  }
   1.117 -
   1.118 -  // We always push rbp, so that on return to interpreter rbp, will be
   1.119 -  // restored correctly and we can correct the stack.
   1.120 -  emit_opcode(cbuf, 0x50 | EBP_enc);
   1.121 -
   1.122 -  if( VerifyStackAtCalls ) { // Majik cookie to verify stack depth
   1.123 -    emit_opcode(cbuf, 0x68); // push 0xbadb100d
   1.124 -    emit_d32(cbuf, 0xbadb100d);
   1.125 -    framesize -= wordSize;
   1.126 -  }
   1.127 -
   1.128 -  if ((C->in_24_bit_fp_mode() || VerifyStackAtCalls ) && framesize < 128 ) {
   1.129 -    if (framesize) {
   1.130 -      emit_opcode(cbuf, 0x83);   // sub  SP,#framesize
   1.131 -      emit_rm(cbuf, 0x3, 0x05, ESP_enc);
   1.132 -      emit_d8(cbuf, framesize);
   1.133 -    }
   1.134 -  } else {
   1.135 -    emit_opcode(cbuf, 0x81);   // sub  SP,#framesize
   1.136 -    emit_rm(cbuf, 0x3, 0x05, ESP_enc);
   1.137 -    emit_d32(cbuf, framesize);
   1.138 -  }
   1.139 +
   1.140 +  __ verified_entry(framesize, C->need_stack_bang(framesize), C->in_24_bit_fp_mode());
   1.141 +
   1.142    C->set_frame_complete(cbuf.insts_size());
   1.143  
   1.144 -#ifdef ASSERT
   1.145 -  if (VerifyStackAtCalls) {
   1.146 -    Label L;
   1.147 -    MacroAssembler masm(&cbuf);
   1.148 -    masm.push(rax);
   1.149 -    masm.mov(rax, rsp);
   1.150 -    masm.andptr(rax, StackAlignmentInBytes-1);
   1.151 -    masm.cmpptr(rax, StackAlignmentInBytes-wordSize);
   1.152 -    masm.pop(rax);
   1.153 -    masm.jcc(Assembler::equal, L);
   1.154 -    masm.stop("Stack is not properly aligned!");
   1.155 -    masm.bind(L);
   1.156 -  }
   1.157 -#endif
   1.158 -
   1.159    if (C->has_mach_constant_base_node()) {
   1.160      // NOTE: We set the table base offset here because users might be
   1.161      // emitted before MachConstantBaseNode.

mercurial