实现getstatic和putstatic

继上次实现了静态方法调用之后,又实现了对静态字段的读写,即getstatic和putstatic指令。通过了下面一段java代码的测试。
public class ClassHasStaticField
{
private static boolean _z;
private static byte _b;
private static char _c;
private static short _si;
private static int _i;
private static float _f;
private static long _l;
private static double _d;
public static void main()
{
_z = true;
boolean z = _z;
if (z != _z) return;
_b = 100;
byte b = _b;
if (b != _b) return;
_si = 300;
short si = _si;
if (si != _si) return;
_c = 'a';
char c =  _c;
if (c != _c) return;
_i = 200;
int i = _i;
if (i != _i) return;
_f = 34.12f;
float f = _f;
if (f != _f) return;
_d = 21.123456;
double d = _d;
if (d != _d) return;
_l = 123456789;
long l = _l;
if (l != _l) return;
}

}

测试时,仍然是先编译这个java类,然后编译和运行虚拟机,源代码请参考附件。

你可能感兴趣的:(jvm jvm实现)