java中madeframe_java字节码中same_frame的含义?

An invokespecial instruction is type safe iff all of the following are true:

...

MethodName is .

Descriptor specifies a void return type.

One can validly pop types matching the argument types given in Descriptor and an uninitialized type, UninitializedArg, off the incoming operand stack, yielding OperandStack.

The outgoing type state is derived from the incoming type state by first replacing the incoming operand stack with OperandStack and then replacing all instances of UninitializedArg with the type of instance being initialized.

instructionIsTypeSafe(invokespecial(CP), Environment, _Offset, StackFrame,

NextStackFrame, ExceptionStackFrame) :-

CP = method(MethodClassName, '', Descriptor),

parseMethodDescriptor(Descriptor, OperandArgList, void),

reverse(OperandArgList, StackArgList),

canPop(StackFrame, StackArgList, TempFrame),

TempFrame = frame(Locals, FullOperandStack, Flags),

FullOperandStack = [UninitializedArg | OperandStack],

currentClassLoader(Environment, CurrentLoader),

rewrittenUninitializedType(UninitializedArg, Environment,

class(MethodClassName, CurrentLoader), This),

rewrittenInitializationFlags(UninitializedArg, Flags, NextFlags),

substitute(UninitializedArg, This, OperandStack, NextOperandStack),

substitute(UninitializedArg, This, Locals, NextLocals),

NextStackFrame = frame(NextLocals, NextOperandStack, NextFlags),

ExceptionStackFrame = frame(Locals, [], Flags),

passesProtectedCheck(Environment, MethodClassName, '',

Descriptor, NextStackFrame).

To compute what type the uninitialized argument's type needs to be rewritten to, there are two cases:If we are initializing an object within its constructor, its type is initially uninitializedThis. This type will be rewritten to the type of the class of the method.

The second case arises from initialization of an object created by new. The uninitialized arg type is rewritten to MethodClass, the type of the method holder of . We check whether there really is a new instruction at Address.

rewrittenUninitializedType(uninitializedThis, Environment,

MethodClass, MethodClass) :-

MethodClass = class(MethodClassName, CurrentLoader),

thisClass(Environment, MethodClass).

rewrittenUninitializedType(uninitializedThis, Environment,

MethodClass, MethodClass) :-

MethodClass = class(MethodClassName, CurrentLoader),

thisClass(Environment, class(thisClassName, thisLoader)),

superclassChain(thisClassName, thisLoader, [MethodClass | Rest]).

rewrittenUninitializedType(uninitialized(Address), Environment,

MethodClass, MethodClass) :-

allInstructions(Environment, Instructions),

member(instruction(Address, new(MethodClass)), Instructions).

rewrittenInitializationFlags(uninitializedThis, _Flags, []).

rewrittenInitializationFlags(uninitialized(_), Flags, Flags).

substitute(_Old, _New, [], []).

substitute(Old, New, [Old | FromRest], [New | ToRest]) :-

substitute(Old, New, FromRest, ToRest).

substitute(Old, New, [From1 | FromRest], [From1 | ToRest]) :-

From1 \= Old,

substitute(Old, New, FromRest, ToRest).

The rule for invokespecial of an method is the sole motivation for passing back a distinct exception stack frame. The concern is that when initializing an object within its constructor, invokespecial can cause a superclass method to be invoked, and that invocation could fail, leaving this uninitialized. This situation cannot be created using source code in the Java programming language, but can be created by programming in bytecode directly.

In this situation, the original frame holds an uninitialized object in local variable 0 and has flag flagThisUninit. Normal termination of invokespecial initializes the uninitialized object and turns off the flagThisUninit flag. But if the invocation of an method throws an exception, the uninitialized object might be left in a partially initialized state, and needs to be made permanently unusable. This is represented by an exception frame containing the broken object (the new value of the local) and the flagThisUninit flag (the old flag). There is no way to get from an apparently-initialized object bearing theflagThisUninit flag to a properly initialized object, so the object is permanently unusable.

If not for this situation, the flags of the exception stack frame would always be the same as the flags of the input stack frame.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值