inside java virtual machine_inside the java virtual machine 再读

The lifetime of a class and an object

Initialization of a class consists of two steps:

init its direct super class, it its direct super class hasn't already inited.

executing the class's class init method, if it has one.

The JVM initializes types on their first active use, Only four activities constitute an active use:

invoking a class initialization method on a new instance of a class,

creating an array whose element type is the class,

invoking a method declared in a class,

and accessing a non-constant field declared in a class or interface. A use of a non-constant field is an active use of only the class or interface that actually declares the field.

When the Java Virtual Machine creates a new instance of a class, either implicitly or explicitly, it first allocates memory on the heap to hold the objectís instance variables. Memory is allocated for all variables declared in the object's class and in all its superclasses, including instance variables that are hidden, a pointer to class data in the method area, are also likely allocated at this point. As soon as the virtual machine has set aside the heap memory for a new object, it immediately initializes the instance variables to default initial values.

The Java compiler generates at least one instance initialization method for every class it compiles. In the Java class file, the instance initialization method is named "

the

an invocation of a superclass

the bytecodes for any instance variable initializers

the bytecodes that implement the body of the corresponding constructor

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值