comparison src/share/vm/prims/jni.cpp @ 2376:c7f3d0b4570f

7017732: move static fields into Class to prepare for perm gen removal Reviewed-by: kvn, coleenp, twisti, stefank
author never
date Fri, 18 Mar 2011 16:00:34 -0700
parents 3582bf76420e
children 0654ee04b214 e1162778c1c8
comparison
equal deleted inserted replaced
2375:d673ef06fe96 2376:c7f3d0b4570f
1 /* 1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
1856 1856
1857 if (isStatic) { 1857 if (isStatic) {
1858 // Static field. The fieldID a JNIid specifying the field holder and the offset within the klassOop. 1858 // Static field. The fieldID a JNIid specifying the field holder and the offset within the klassOop.
1859 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID); 1859 JNIid* id = jfieldIDWorkaround::from_static_jfieldID(fieldID);
1860 assert(id->is_static_field_id(), "invalid static field id"); 1860 assert(id->is_static_field_id(), "invalid static field id");
1861 found = instanceKlass::cast(id->holder())->find_local_field_from_offset(id->offset(), true, &fd); 1861 found = id->find_local_field(&fd);
1862 } else { 1862 } else {
1863 // Non-static field. The fieldID is really the offset of the field within the instanceOop. 1863 // Non-static field. The fieldID is really the offset of the field within the instanceOop.
1864 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID); 1864 int offset = jfieldIDWorkaround::from_instance_jfieldID(k, fieldID);
1865 found = instanceKlass::cast(k)->find_field_from_offset(offset, false, &fd); 1865 found = instanceKlass::cast(k)->find_field_from_offset(offset, false, &fd);
1866 } 1866 }
1904 1904
1905 // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the klassOop 1905 // A jfieldID for a static field is a JNIid specifying the field holder and the offset within the klassOop
1906 JNIid* id = instanceKlass::cast(fd.field_holder())->jni_id_for(fd.offset()); 1906 JNIid* id = instanceKlass::cast(fd.field_holder())->jni_id_for(fd.offset());
1907 debug_only(id->set_is_static_field_id();) 1907 debug_only(id->set_is_static_field_id();)
1908 1908
1909 debug_only(int first_offset = instanceKlass::cast(fd.field_holder())->offset_of_static_fields();) 1909 debug_only(id->verify(fd.field_holder()));
1910 debug_only(int end_offset = first_offset + (instanceKlass::cast(fd.field_holder())->static_field_size() * wordSize);)
1911 assert(id->offset() >= first_offset && id->offset() < end_offset, "invalid static field offset");
1912 1910
1913 ret = jfieldIDWorkaround::to_static_jfieldID(id); 1911 ret = jfieldIDWorkaround::to_static_jfieldID(id);
1914 return ret; 1912 return ret;
1915 JNI_END 1913 JNI_END
1916 1914
1926 // Keep JVMTI addition small and only check enabled flag here. 1924 // Keep JVMTI addition small and only check enabled flag here.
1927 // jni_GetField_probe() assumes that is okay to create handles. 1925 // jni_GetField_probe() assumes that is okay to create handles.
1928 if (JvmtiExport::should_post_field_access()) { 1926 if (JvmtiExport::should_post_field_access()) {
1929 JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); 1927 JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true);
1930 } 1928 }
1931 jobject ret = JNIHandles::make_local(id->holder()->obj_field(id->offset())); 1929 jobject ret = JNIHandles::make_local(id->holder()->java_mirror()->obj_field(id->offset()));
1932 DTRACE_PROBE1(hotspot_jni, GetStaticObjectField__return, ret); 1930 DTRACE_PROBE1(hotspot_jni, GetStaticObjectField__return, ret);
1933 return ret; 1931 return ret;
1934 JNI_END 1932 JNI_END
1935 1933
1936 #define DEFINE_GETSTATICFIELD(Return,Fieldname,Result) \ 1934 #define DEFINE_GETSTATICFIELD(Return,Fieldname,Result) \
1948 /* Keep JVMTI addition small and only check enabled flag here. */ \ 1946 /* Keep JVMTI addition small and only check enabled flag here. */ \
1949 /* jni_GetField_probe() assumes that is okay to create handles. */ \ 1947 /* jni_GetField_probe() assumes that is okay to create handles. */ \
1950 if (JvmtiExport::should_post_field_access()) { \ 1948 if (JvmtiExport::should_post_field_access()) { \
1951 JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); \ 1949 JvmtiExport::jni_GetField_probe(thread, NULL, NULL, id->holder(), fieldID, true); \
1952 } \ 1950 } \
1953 ret = id->holder()-> Fieldname##_field (id->offset()); \ 1951 ret = id->holder()->java_mirror()-> Fieldname##_field (id->offset()); \
1954 return ret;\ 1952 return ret;\
1955 JNI_END 1953 JNI_END
1956 1954
1957 DEFINE_GETSTATICFIELD(jboolean, bool, Boolean) 1955 DEFINE_GETSTATICFIELD(jboolean, bool, Boolean)
1958 DEFINE_GETSTATICFIELD(jbyte, byte, Byte) 1956 DEFINE_GETSTATICFIELD(jbyte, byte, Byte)
1974 if (JvmtiExport::should_post_field_modification()) { 1972 if (JvmtiExport::should_post_field_modification()) {
1975 jvalue field_value; 1973 jvalue field_value;
1976 field_value.l = value; 1974 field_value.l = value;
1977 JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, 'L', (jvalue *)&field_value); 1975 JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, 'L', (jvalue *)&field_value);
1978 } 1976 }
1979 id->holder()->obj_field_put(id->offset(), JNIHandles::resolve(value)); 1977 id->holder()->java_mirror()->obj_field_put(id->offset(), JNIHandles::resolve(value));
1980 DTRACE_PROBE(hotspot_jni, SetStaticObjectField__return); 1978 DTRACE_PROBE(hotspot_jni, SetStaticObjectField__return);
1981 JNI_END 1979 JNI_END
1982 1980
1983 1981
1984 #define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType) \ 1982 #define DEFINE_SETSTATICFIELD(Argument,Fieldname,Result,SigType,unionType) \
1997 if (JvmtiExport::should_post_field_modification()) { \ 1995 if (JvmtiExport::should_post_field_modification()) { \
1998 jvalue field_value; \ 1996 jvalue field_value; \
1999 field_value.unionType = value; \ 1997 field_value.unionType = value; \
2000 JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, SigType, (jvalue *)&field_value); \ 1998 JvmtiExport::jni_SetField_probe(thread, NULL, NULL, id->holder(), fieldID, true, SigType, (jvalue *)&field_value); \
2001 } \ 1999 } \
2002 id->holder()-> Fieldname##_field_put (id->offset(), value); \ 2000 id->holder()->java_mirror()-> Fieldname##_field_put (id->offset(), value); \
2003 DTRACE_PROBE(hotspot_jni, SetStatic##Result##Field__return);\ 2001 DTRACE_PROBE(hotspot_jni, SetStatic##Result##Field__return);\
2004 JNI_END 2002 JNI_END
2005 2003
2006 DEFINE_SETSTATICFIELD(jboolean, bool, Boolean, 'Z', z) 2004 DEFINE_SETSTATICFIELD(jboolean, bool, Boolean, 'Z', z)
2007 DEFINE_SETSTATICFIELD(jbyte, byte, Byte, 'B', b) 2005 DEFINE_SETSTATICFIELD(jbyte, byte, Byte, 'B', b)