打开eclipse编译后的.class文件
众所周知,用文本编辑器打开.class文件会乱码。我们可以使用命令行打开.class文件
项目结构:
代码:
public class Synchronized { public static void main(String[] args) { // 对Synchronized Class对象进行加锁 synchronized (Synchronized.class) { } // 静态同步方法,对Synchronized Class对象进行加锁 m(); } public static synchronized void m() { } }
cmd到~\ThreadTest\bin\testnew,即cmd到.class文件的同级目录下(.class文件在项目路径下的bin文件夹下),执行:javap -v Synchronized.class
可以看到Synchronized.class文件内容如下:
public static void main(java.lang.String[]); descriptor: ([Ljava/lang/String;)V flags: ACC_PUBLIC, ACC_STATIC Code: stack=2, locals=1, args_size=1 0: ldc #1 // class testnew/Synchronized 2: dup 3: monitorenter 4: monitorexit 5: invokestatic #16 // Method m:()V 8: return LineNumberTable: line 6: 0 line 10: 5 line 11: 8 LocalVariableTable: Start Length Slot Name Signature 0 9 0 args [Ljava/lang/String; public static synchronized void m(); descriptor: ()V flags: ACC_PUBLIC, ACC_STATIC, ACC_SYNCHRONIZED Code: stack=0, locals=0, args_size=0 0: return LineNumberTable: line 14: 0 LocalVariableTable: Start Length Slot Name Signature