我正在查看Javap的输出。例如:
这段代码
final Foo foo = new Foo(1,2);
...
new Callable<Integer>()
{
@Override
public Integer call() throws Exception
{
return foo.doSomething();
}生成:
jvmOperations": [{
"byteOffset": 0,
"constantPoolIndex": null,
"opCode": 42,
"opCodeName": "aload_0",
"type": null,
"tagName": null,
"tagValue": null
}, {
"byteOffset": 1,
"constantPoolIndex": null,
"opCode": 180,
"opCodeName": "getfield",
"type": null,
"tagName": "Field",
"tagValue": "val$foo:Lcom/example/graph/demo/Foo;"
}, {
"byteOffset": 4,
"constantPoolIndex": null,
"opCode": 182,
"opCodeName": "invokevirtual",
"type": null,
"tagName": "Method",
"tagValue": "com/example/graph/demo/Foo.doSomething:()Ljava/lang/Integer;"
}, {
"byteOffset": 7,
"constantPoolIndex": null,
"opCode": 176,
"opCodeName": "areturn",
"type": null,
"tagName": null,
"tagValue": null
}]因此,我看到对象在本例中是由val$foo标识的。在类元数据中
"classMetaData": {
"classId": "com/example/Main$1.class",
"sourceName": "Main.java",
"isInterface": false,
"isClass": true,
"accessModifiers": ["final"],
"superClassName": "java/lang/Object",
"implementedInterfaces": ["java/util/concurrent/Callable"],
"jreTargetVersion": "51.0",
"fields": ["val$foo"],
"fieldModifiers": {
"val$foo": ["final"]
},
"methodInformationMap": {},
"interface": false,
"class": true
}, 但是现在我想了解更多关于原始对象foo的信息。例如,我知道它在其一个字段中包含了这些数据:
{
"byteOffset": 37,
"constantPoolIndex": null,
"opCode": 18,
"opCodeName": "ldc",
"type": null,
"tagName": "String",
"tagValue": "NODE-1"
}, JVM如何知道val$foo指向什么?
发布于 2014-10-22 00:11:00
您需要更多的上下文来跟踪JVM为foo存储的值。
假设foo是局部变量
new Foo(1,2);foo中。foo的值的副本将被检索并推送到堆栈上。val$foo字段(该变量即将关闭)foo.something()时,JVM检索匿名类实例的字段val$foo的值。https://stackoverflow.com/questions/26498264
复制相似问题