comparison src/share/vm/prims/jvm.cpp @ 12355:cefad50507d8

Merge with hs25-b53
author Gilles Duboscq <duboscq@ssw.jku.at>
date Fri, 11 Oct 2013 10:38:03 +0200
parents e636d62005c3 a07c25e4f67e
children 096c224171c4
comparison
equal deleted inserted replaced
12058:ccb4f2af2319 12355:cefad50507d8
1835 int offset = fs.offset(); 1835 int offset = fs.offset();
1836 if (offset == java_lang_Throwable::get_backtrace_offset()) continue; 1836 if (offset == java_lang_Throwable::get_backtrace_offset()) continue;
1837 } 1837 }
1838 1838
1839 if (!publicOnly || fs.access_flags().is_public()) { 1839 if (!publicOnly || fs.access_flags().is_public()) {
1840 fd.initialize(k(), fs.index()); 1840 fd.reinitialize(k(), fs.index());
1841 oop field = Reflection::new_field(&fd, UseNewReflection, CHECK_NULL); 1841 oop field = Reflection::new_field(&fd, UseNewReflection, CHECK_NULL);
1842 result->obj_at_put(out_idx, field); 1842 result->obj_at_put(out_idx, field);
1843 ++out_idx; 1843 ++out_idx;
1844 } 1844 }
1845 } 1845 }
1846 assert(out_idx == num_fields, "just checking"); 1846 assert(out_idx == num_fields, "just checking");
1847 return (jobjectArray) JNIHandles::make_local(env, result()); 1847 return (jobjectArray) JNIHandles::make_local(env, result());
1848 } 1848 }
1849 JVM_END 1849 JVM_END
1850 1850
1851 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly)) 1851 static bool select_method(methodHandle method, bool want_constructor) {
1852 { 1852 if (want_constructor) {
1853 JVMWrapper("JVM_GetClassDeclaredMethods"); 1853 return (method->is_initializer() && !method->is_static());
1854 } else {
1855 return (!method->is_initializer() && !method->is_overpass());
1856 }
1857 }
1858
1859 static jobjectArray get_class_declared_methods_helper(
1860 JNIEnv *env,
1861 jclass ofClass, jboolean publicOnly,
1862 bool want_constructor,
1863 Klass* klass, TRAPS) {
1864
1854 JvmtiVMObjectAllocEventCollector oam; 1865 JvmtiVMObjectAllocEventCollector oam;
1855 1866
1856 // Exclude primitive types and array types 1867 // Exclude primitive types and array types
1857 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) 1868 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass))
1858 || java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_array()) { 1869 || java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_array()) {
1859 // Return empty array 1870 // Return empty array
1860 oop res = oopFactory::new_objArray(SystemDictionary::reflect_Method_klass(), 0, CHECK_NULL); 1871 oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);
1861 return (jobjectArray) JNIHandles::make_local(env, res); 1872 return (jobjectArray) JNIHandles::make_local(env, res);
1862 } 1873 }
1863 1874
1864 instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))); 1875 instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
1865 1876
1866 // Ensure class is linked 1877 // Ensure class is linked
1867 k->link_class(CHECK_NULL); 1878 k->link_class(CHECK_NULL);
1868 1879
1869 Array<Method*>* methods = k->methods(); 1880 Array<Method*>* methods = k->methods();
1870 int methods_length = methods->length(); 1881 int methods_length = methods->length();
1882
1883 // Save original method_idnum in case of redefinition, which can change
1884 // the idnum of obsolete methods. The new method will have the same idnum
1885 // but if we refresh the methods array, the counts will be wrong.
1886 ResourceMark rm(THREAD);
1887 GrowableArray<int>* idnums = new GrowableArray<int>(methods_length);
1871 int num_methods = 0; 1888 int num_methods = 0;
1872 1889
1873 int i; 1890 for (int i = 0; i < methods_length; i++) {
1874 for (i = 0; i < methods_length; i++) {
1875 methodHandle method(THREAD, methods->at(i)); 1891 methodHandle method(THREAD, methods->at(i));
1876 if (!method->is_initializer() && !method->is_overpass()) { 1892 if (select_method(method, want_constructor)) {
1877 if (!publicOnly || method->is_public()) { 1893 if (!publicOnly || method->is_public()) {
1894 idnums->push(method->method_idnum());
1878 ++num_methods; 1895 ++num_methods;
1879 } 1896 }
1880 } 1897 }
1881 } 1898 }
1882 1899
1883 // Allocate result 1900 // Allocate result
1884 objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Method_klass(), num_methods, CHECK_NULL); 1901 objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1885 objArrayHandle result (THREAD, r); 1902 objArrayHandle result (THREAD, r);
1886 1903
1887 int out_idx = 0; 1904 // Now just put the methods that we selected above, but go by their idnum
1888 for (i = 0; i < methods_length; i++) { 1905 // in case of redefinition. The methods can be redefined at any safepoint,
1889 methodHandle method(THREAD, methods->at(i)); 1906 // so above when allocating the oop array and below when creating reflect
1890 if (!method->is_initializer() && !method->is_overpass()) { 1907 // objects.
1891 if (!publicOnly || method->is_public()) { 1908 for (int i = 0; i < num_methods; i++) {
1892 oop m = Reflection::new_method(method, UseNewReflection, false, CHECK_NULL); 1909 methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1893 result->obj_at_put(out_idx, m); 1910 if (method.is_null()) {
1894 ++out_idx; 1911 // Method may have been deleted and seems this API can handle null
1912 // Otherwise should probably put a method that throws NSME
1913 result->obj_at_put(i, NULL);
1914 } else {
1915 oop m;
1916 if (want_constructor) {
1917 m = Reflection::new_constructor(method, CHECK_NULL);
1918 } else {
1919 m = Reflection::new_method(method, UseNewReflection, false, CHECK_NULL);
1895 } 1920 }
1896 } 1921 result->obj_at_put(i, m);
1897 } 1922 }
1898 assert(out_idx == num_methods, "just checking"); 1923 }
1924
1899 return (jobjectArray) JNIHandles::make_local(env, result()); 1925 return (jobjectArray) JNIHandles::make_local(env, result());
1926 }
1927
1928 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1929 {
1930 JVMWrapper("JVM_GetClassDeclaredMethods");
1931 return get_class_declared_methods_helper(env, ofClass, publicOnly,
1932 /*want_constructor*/ false,
1933 SystemDictionary::reflect_Method_klass(), THREAD);
1900 } 1934 }
1901 JVM_END 1935 JVM_END
1902 1936
1903 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly)) 1937 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1904 { 1938 {
1905 JVMWrapper("JVM_GetClassDeclaredConstructors"); 1939 JVMWrapper("JVM_GetClassDeclaredConstructors");
1906 JvmtiVMObjectAllocEventCollector oam; 1940 return get_class_declared_methods_helper(env, ofClass, publicOnly,
1907 1941 /*want_constructor*/ true,
1908 // Exclude primitive types and array types 1942 SystemDictionary::reflect_Constructor_klass(), THREAD);
1909 if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass))
1910 || java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_array()) {
1911 // Return empty array
1912 oop res = oopFactory::new_objArray(SystemDictionary::reflect_Constructor_klass(), 0 , CHECK_NULL);
1913 return (jobjectArray) JNIHandles::make_local(env, res);
1914 }
1915
1916 instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
1917
1918 // Ensure class is linked
1919 k->link_class(CHECK_NULL);
1920
1921 Array<Method*>* methods = k->methods();
1922 int methods_length = methods->length();
1923 int num_constructors = 0;
1924
1925 int i;
1926 for (i = 0; i < methods_length; i++) {
1927 methodHandle method(THREAD, methods->at(i));
1928 if (method->is_initializer() && !method->is_static()) {
1929 if (!publicOnly || method->is_public()) {
1930 ++num_constructors;
1931 }
1932 }
1933 }
1934
1935 // Allocate result
1936 objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Constructor_klass(), num_constructors, CHECK_NULL);
1937 objArrayHandle result(THREAD, r);
1938
1939 int out_idx = 0;
1940 for (i = 0; i < methods_length; i++) {
1941 methodHandle method(THREAD, methods->at(i));
1942 if (method->is_initializer() && !method->is_static()) {
1943 if (!publicOnly || method->is_public()) {
1944 oop m = Reflection::new_constructor(method, CHECK_NULL);
1945 result->obj_at_put(out_idx, m);
1946 ++out_idx;
1947 }
1948 }
1949 }
1950 assert(out_idx == num_constructors, "just checking");
1951 return (jobjectArray) JNIHandles::make_local(env, result());
1952 } 1943 }
1953 JVM_END 1944 JVM_END
1954 1945
1955 JVM_ENTRY(jint, JVM_GetClassAccessFlags(JNIEnv *env, jclass cls)) 1946 JVM_ENTRY(jint, JVM_GetClassAccessFlags(JNIEnv *env, jclass cls))
1956 { 1947 {
4246 JNIEXPORT void JNICALL JVM_VMBreakPoint(JNIEnv *env, jobject obj); 4237 JNIEXPORT void JNICALL JVM_VMBreakPoint(JNIEnv *env, jobject obj);
4247 } 4238 }
4248 4239
4249 JVM_LEAF(jboolean, JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get)) 4240 JVM_LEAF(jboolean, JVM_AccessVMBooleanFlag(const char* name, jboolean* value, jboolean is_get))
4250 JVMWrapper("JVM_AccessBoolVMFlag"); 4241 JVMWrapper("JVM_AccessBoolVMFlag");
4251 return is_get ? CommandLineFlags::boolAt((char*) name, (bool*) value) : CommandLineFlags::boolAtPut((char*) name, (bool*) value, INTERNAL); 4242 return is_get ? CommandLineFlags::boolAt((char*) name, (bool*) value) : CommandLineFlags::boolAtPut((char*) name, (bool*) value, Flag::INTERNAL);
4252 JVM_END 4243 JVM_END
4253 4244
4254 JVM_LEAF(jboolean, JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get)) 4245 JVM_LEAF(jboolean, JVM_AccessVMIntFlag(const char* name, jint* value, jboolean is_get))
4255 JVMWrapper("JVM_AccessVMIntFlag"); 4246 JVMWrapper("JVM_AccessVMIntFlag");
4256 intx v; 4247 intx v;
4257 jboolean result = is_get ? CommandLineFlags::intxAt((char*) name, &v) : CommandLineFlags::intxAtPut((char*) name, &v, INTERNAL); 4248 jboolean result = is_get ? CommandLineFlags::intxAt((char*) name, &v) : CommandLineFlags::intxAtPut((char*) name, &v, Flag::INTERNAL);
4258 *value = (jint)v; 4249 *value = (jint)v;
4259 return result; 4250 return result;
4260 JVM_END 4251 JVM_END
4261 4252
4262 4253