< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page




  36 #include "classfile/symbolTable.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/vmSymbols.hpp"
  39 #include "gc/shared/collectedHeap.inline.hpp"
  40 #include "interpreter/bytecode.hpp"
  41 #include "jfr/jfrEvents.hpp"
  42 #include "logging/log.hpp"
  43 #include "memory/heapShared.hpp"
  44 #include "memory/oopFactory.hpp"
  45 #include "memory/referenceType.hpp"
  46 #include "memory/resourceArea.hpp"
  47 #include "memory/universe.hpp"
  48 #include "oops/access.inline.hpp"
  49 #include "oops/constantPool.hpp"
  50 #include "oops/fieldStreams.hpp"
  51 #include "oops/instanceKlass.hpp"
  52 #include "oops/method.hpp"
  53 #include "oops/objArrayKlass.hpp"
  54 #include "oops/objArrayOop.inline.hpp"
  55 #include "oops/oop.inline.hpp"

  56 #include "prims/jvm_misc.hpp"
  57 #include "prims/jvmtiExport.hpp"
  58 #include "prims/jvmtiThreadState.hpp"
  59 #include "prims/nativeLookup.hpp"
  60 #include "prims/stackwalk.hpp"
  61 #include "runtime/arguments.hpp"
  62 #include "runtime/atomic.hpp"
  63 #include "runtime/handles.inline.hpp"
  64 #include "runtime/init.hpp"
  65 #include "runtime/interfaceSupport.inline.hpp"
  66 #include "runtime/deoptimization.hpp"
  67 #include "runtime/handshake.hpp"
  68 #include "runtime/java.hpp"
  69 #include "runtime/javaCalls.hpp"
  70 #include "runtime/jfieldIDWorkaround.hpp"
  71 #include "runtime/jniHandles.inline.hpp"
  72 #include "runtime/orderAccess.hpp"
  73 #include "runtime/os.inline.hpp"
  74 #include "runtime/perfData.hpp"
  75 #include "runtime/reflection.hpp"


1643   }
1644 
1645   objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), num_fields, CHECK_NULL);
1646   objArrayHandle result (THREAD, r);
1647 
1648   int out_idx = 0;
1649   fieldDescriptor fd;
1650   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
1651     if (!publicOnly || fs.access_flags().is_public()) {
1652       fd.reinitialize(k, fs.index());
1653       oop field = Reflection::new_field(&fd, CHECK_NULL);
1654       result->obj_at_put(out_idx, field);
1655       ++out_idx;
1656     }
1657   }
1658   assert(out_idx == num_fields, "just checking");
1659   return (jobjectArray) JNIHandles::make_local(env, result());
1660 }
1661 JVM_END
1662 











































1663 static bool select_method(const methodHandle& method, bool want_constructor) {
1664   if (want_constructor) {
1665     return (method->is_initializer() && !method->is_static());
1666   } else {
1667     return  (!method->is_initializer() && !method->is_overpass());
1668   }
1669 }
1670 
1671 static jobjectArray get_class_declared_methods_helper(
1672                                   JNIEnv *env,
1673                                   jclass ofClass, jboolean publicOnly,
1674                                   bool want_constructor,
1675                                   Klass* klass, TRAPS) {
1676 
1677   JvmtiVMObjectAllocEventCollector oam;
1678 
1679   // Exclude primitive types and array types
1680   if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass))
1681       || java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->is_array_klass()) {
1682     // Return empty array


1838                                 nest_host_k->external_name()
1839                            );
1840              return NULL;
1841            }
1842          }
1843          else {
1844            // we have a bad nest member entry - throw ICCE
1845            ResourceMark rm(THREAD);
1846            Exceptions::fthrow(THREAD_AND_LOCATION,
1847                               icce,
1848                               "Class %s can not be a nest member of %s",
1849                               k->external_name(),
1850                               host->external_name()
1851                               );
1852            return NULL;
1853          }
1854       }
1855     }
1856     else {
1857       assert(host == ck, "must be singleton nest");






































1858     }
1859     return (jobjectArray)JNIHandles::make_local(THREAD, result());
1860   }
1861 }
1862 JVM_END
1863 
1864 // Constant pool access //////////////////////////////////////////////////////////
1865 
1866 JVM_ENTRY(jobject, JVM_GetClassConstantPool(JNIEnv *env, jclass cls))
1867 {
1868   JVMWrapper("JVM_GetClassConstantPool");
1869   JvmtiVMObjectAllocEventCollector oam;
1870 
1871   // Return null for primitives and arrays
1872   if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
1873     Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
1874     if (k->is_instance_klass()) {
1875       InstanceKlass* k_h = InstanceKlass::cast(k);
1876       Handle jcp = reflect_ConstantPool::create(CHECK_NULL);
1877       reflect_ConstantPool::set_cp(jcp(), k_h->constants());




  36 #include "classfile/symbolTable.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/vmSymbols.hpp"
  39 #include "gc/shared/collectedHeap.inline.hpp"
  40 #include "interpreter/bytecode.hpp"
  41 #include "jfr/jfrEvents.hpp"
  42 #include "logging/log.hpp"
  43 #include "memory/heapShared.hpp"
  44 #include "memory/oopFactory.hpp"
  45 #include "memory/referenceType.hpp"
  46 #include "memory/resourceArea.hpp"
  47 #include "memory/universe.hpp"
  48 #include "oops/access.inline.hpp"
  49 #include "oops/constantPool.hpp"
  50 #include "oops/fieldStreams.hpp"
  51 #include "oops/instanceKlass.hpp"
  52 #include "oops/method.hpp"
  53 #include "oops/objArrayKlass.hpp"
  54 #include "oops/objArrayOop.inline.hpp"
  55 #include "oops/oop.inline.hpp"
  56 #include "oops/recordParamStreams.hpp"
  57 #include "prims/jvm_misc.hpp"
  58 #include "prims/jvmtiExport.hpp"
  59 #include "prims/jvmtiThreadState.hpp"
  60 #include "prims/nativeLookup.hpp"
  61 #include "prims/stackwalk.hpp"
  62 #include "runtime/arguments.hpp"
  63 #include "runtime/atomic.hpp"
  64 #include "runtime/handles.inline.hpp"
  65 #include "runtime/init.hpp"
  66 #include "runtime/interfaceSupport.inline.hpp"
  67 #include "runtime/deoptimization.hpp"
  68 #include "runtime/handshake.hpp"
  69 #include "runtime/java.hpp"
  70 #include "runtime/javaCalls.hpp"
  71 #include "runtime/jfieldIDWorkaround.hpp"
  72 #include "runtime/jniHandles.inline.hpp"
  73 #include "runtime/orderAccess.hpp"
  74 #include "runtime/os.inline.hpp"
  75 #include "runtime/perfData.hpp"
  76 #include "runtime/reflection.hpp"


1644   }
1645 
1646   objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), num_fields, CHECK_NULL);
1647   objArrayHandle result (THREAD, r);
1648 
1649   int out_idx = 0;
1650   fieldDescriptor fd;
1651   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
1652     if (!publicOnly || fs.access_flags().is_public()) {
1653       fd.reinitialize(k, fs.index());
1654       oop field = Reflection::new_field(&fd, CHECK_NULL);
1655       result->obj_at_put(out_idx, field);
1656       ++out_idx;
1657     }
1658   }
1659   assert(out_idx == num_fields, "just checking");
1660   return (jobjectArray) JNIHandles::make_local(env, result());
1661 }
1662 JVM_END
1663 
1664 JVM_ENTRY(jobjectArray, JVM_GetRecordComponentNames(JNIEnv *env, jclass ofClass))
1665 {
1666   // current is not a primitive or array class
1667   JVMWrapper("JVM_GetRecordComponentNames");
1668   JvmtiVMObjectAllocEventCollector oam;
1669 
1670   InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));
1671   constantPoolHandle cp(THREAD, k->constants());
1672 
1673   // Ensure class is linked
1674   k->link_class(CHECK_NULL);
1675 
1676   // Allocate result
1677   int num_record_params = k->record_params_count();
1678   Array<u2>* record_parameters = k->record_params();
1679   // DEBUG
1680   //tty->print_cr("num_record_params == %d", num_record_params);
1681 
1682   if (num_record_params <= 0) {
1683     oop res = oopFactory::new_objArray(SystemDictionary::String_klass(), 0, CHECK_NULL);
1684     return (jobjectArray) JNIHandles::make_local(env, res);
1685   }
1686 
1687   objArrayOop  dest_o = oopFactory::new_objArray(SystemDictionary::String_klass(), num_record_params, CHECK_NULL);
1688   objArrayHandle dest(THREAD, dest_o);
1689 
1690   int out_idx = 0;
1691   for (JavaRecordParameterStream recordParamsStream(k); !recordParamsStream.done(); recordParamsStream.next()) {
1692     Handle str = java_lang_String::create_from_symbol(recordParamsStream.name() , CHECK_NULL);
1693     dest->obj_at_put(out_idx, str());
1694     ++out_idx;
1695   }
1696   assert(out_idx == num_record_params, "just checking");
1697   return (jobjectArray) JNIHandles::make_local(dest());
1698 }
1699 JVM_END
1700 
1701 JVM_ENTRY(jboolean, JVM_IsRecord(JNIEnv *env, jclass cls))
1702   JVMWrapper("JVM_IsRecord");
1703   InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls)));
1704   return (jboolean) (k->record_params_count() >= 0);
1705 JVM_END
1706 
1707 static bool select_method(const methodHandle& method, bool want_constructor) {
1708   if (want_constructor) {
1709     return (method->is_initializer() && !method->is_static());
1710   } else {
1711     return  (!method->is_initializer() && !method->is_overpass());
1712   }
1713 }
1714 
1715 static jobjectArray get_class_declared_methods_helper(
1716                                   JNIEnv *env,
1717                                   jclass ofClass, jboolean publicOnly,
1718                                   bool want_constructor,
1719                                   Klass* klass, TRAPS) {
1720 
1721   JvmtiVMObjectAllocEventCollector oam;
1722 
1723   // Exclude primitive types and array types
1724   if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass))
1725       || java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->is_array_klass()) {
1726     // Return empty array


1882                                 nest_host_k->external_name()
1883                            );
1884              return NULL;
1885            }
1886          }
1887          else {
1888            // we have a bad nest member entry - throw ICCE
1889            ResourceMark rm(THREAD);
1890            Exceptions::fthrow(THREAD_AND_LOCATION,
1891                               icce,
1892                               "Class %s can not be a nest member of %s",
1893                               k->external_name(),
1894                               host->external_name()
1895                               );
1896            return NULL;
1897          }
1898       }
1899     }
1900     else {
1901       assert(host == ck, "must be singleton nest");
1902     }
1903     return (jobjectArray)JNIHandles::make_local(THREAD, result());
1904   }
1905 }
1906 JVM_END
1907 
1908 JVM_ENTRY(jobjectArray, JVM_GetPermittedSubtypes(JNIEnv* env, jclass current))
1909 {
1910   JVMWrapper("JVM_GetPermittedSubtypes");
1911   Klass* c = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(current));
1912   assert(c->is_instance_klass(), "must be");
1913   InstanceKlass* ck = InstanceKlass::cast(c);
1914   Symbol* icce = vmSymbols::java_lang_IncompatibleClassChangeError();
1915   {
1916     JvmtiVMObjectAllocEventCollector oam;
1917     Array<u2>* subtypes = ck->permitted_subtypes();
1918     int length = subtypes == NULL ? 0 : subtypes->length();
1919     if (length == 0) {
1920         return NULL;
1921     }
1922     objArrayOop r = oopFactory::new_objArray(SystemDictionary::Class_klass(), length, CHECK_NULL);
1923     objArrayHandle result (THREAD, r);
1924     int i;
1925     for (i = 0; i < length; i++) {
1926       int cp_index = subtypes->at(i);
1927       Klass* k = ck->constants()->klass_at(cp_index, CHECK_NULL);
1928       if (k->is_instance_klass()) {
1929         result->obj_at_put(i, k->java_mirror());
1930       } else {
1931         ResourceMark rm(THREAD);
1932         Exceptions::fthrow(THREAD_AND_LOCATION,
1933                            icce,
1934                            "Class %s can not be a permitted subtype of %s",
1935                            k->external_name(),
1936                            ck->external_name()
1937                            );
1938         return NULL;
1939       }
1940     }
1941     return (jobjectArray)JNIHandles::make_local(THREAD, result());
1942   }
1943 }
1944 JVM_END
1945 
1946 // Constant pool access //////////////////////////////////////////////////////////
1947 
1948 JVM_ENTRY(jobject, JVM_GetClassConstantPool(JNIEnv *env, jclass cls))
1949 {
1950   JVMWrapper("JVM_GetClassConstantPool");
1951   JvmtiVMObjectAllocEventCollector oam;
1952 
1953   // Return null for primitives and arrays
1954   if (!java_lang_Class::is_primitive(JNIHandles::resolve_non_null(cls))) {
1955     Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
1956     if (k->is_instance_klass()) {
1957       InstanceKlass* k_h = InstanceKlass::cast(k);
1958       Handle jcp = reflect_ConstantPool::create(CHECK_NULL);
1959       reflect_ConstantPool::set_cp(jcp(), k_h->constants());


< prev index next >