< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page
@@ -54,10 +54,11 @@
  #include "memory/resourceArea.hpp"
  #include "memory/universe.hpp"
  #include "oops/access.inline.hpp"
  #include "oops/constantPool.hpp"
  #include "oops/fieldStreams.inline.hpp"
+ #include "oops/flatArrayKlass.hpp"
  #include "oops/instanceKlass.hpp"
  #include "oops/klass.inline.hpp"
  #include "oops/method.hpp"
  #include "oops/recordComponent.hpp"
  #include "oops/objArrayKlass.hpp"

@@ -596,11 +597,32 @@
  // java.lang.Object ///////////////////////////////////////////////
  
  
  JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
    // as implemented in the classic virtual machine; return 0 if object is NULL
-   return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ;
+   if (handle == NULL) {
+     return 0;
+   }
+   oop obj = JNIHandles::resolve_non_null(handle);
+   if (EnableValhalla && obj->klass()->is_inline_klass()) {
+       JavaValue result(T_INT);
+       JavaCallArguments args;
+       Handle ho(THREAD, obj);
+       args.push_oop(ho);
+       methodHandle method(THREAD, Universe::primitive_type_hash_code_method());
+       JavaCalls::call(&result, method, &args, THREAD);
+       if (HAS_PENDING_EXCEPTION) {
+         if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
+           Handle e(THREAD, PENDING_EXCEPTION);
+           CLEAR_PENDING_EXCEPTION;
+           THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in hashCode", e, false);
+         }
+       }
+       return result.get_jint();
+   } else {
+     return ObjectSynchronizer::FastHashCode(THREAD, obj);
+   }
  JVM_END
  
  
  JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
    Handle obj(THREAD, JNIHandles::resolve_non_null(handle));

@@ -648,10 +670,11 @@
  
    // Check if class of obj supports the Cloneable interface.
    // All arrays are considered to be cloneable (See JLS 20.1.5).
    // All j.l.r.Reference classes are considered non-cloneable.
    if (!klass->is_cloneable() ||
+        klass->is_inline_klass() ||
        (klass->is_instance_klass() &&
         InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
      ResourceMark rm(THREAD);
      THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
    }

@@ -1145,30 +1168,33 @@
  
    Klass* klass = java_lang_Class::as_Klass(mirror);
    // Figure size of result array
    int size;
    if (klass->is_instance_klass()) {
-     size = InstanceKlass::cast(klass)->local_interfaces()->length();
+     InstanceKlass* ik = InstanceKlass::cast(klass);
+     size = ik->local_interfaces()->length();
    } else {
-     assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass");
-     size = 2;
+     assert(klass->is_objArray_klass() || klass->is_typeArray_klass() || klass->is_flatArray_klass(), "Illegal mirror klass");
+     size = 3;
    }
  
    // Allocate result array
    objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
    objArrayHandle result (THREAD, r);
    // Fill in result
    if (klass->is_instance_klass()) {
      // Regular instance klass, fill in all local interfaces
      for (int index = 0; index < size; index++) {
-       Klass* k = InstanceKlass::cast(klass)->local_interfaces()->at(index);
+       InstanceKlass* ik = InstanceKlass::cast(klass);
+       Klass* k = ik->local_interfaces()->at(index);
        result->obj_at_put(index, k->java_mirror());
      }
    } else {
-     // All arrays implement java.lang.Cloneable and java.io.Serializable
+     // All arrays implement java.lang.Cloneable, java.io.Serializable and java.lang.IdentityObject
      result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
      result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
+     result->obj_at_put(2, vmClasses::IdentityObject_klass()->java_mirror());
    }
    return (jobjectArray) JNIHandles::make_local(THREAD, result());
  JVM_END
  
  

@@ -1760,14 +1786,18 @@
    return NULL;
  }
  JVM_END
  
  static bool select_method(const methodHandle& method, bool want_constructor) {
+   bool is_ctor = (method->is_object_constructor() ||
+                   method->is_static_init_factory());
    if (want_constructor) {
-     return (method->is_initializer() && !method->is_static());
+     return is_ctor;
    } else {
-     return  (!method->is_initializer() && !method->is_overpass());
+     return (!is_ctor &&
+             !method->is_class_initializer() &&
+             !method->is_overpass());
    }
  }
  
  static jobjectArray get_class_declared_methods_helper(
                                    JNIEnv *env,

@@ -1826,10 +1856,12 @@
        // Otherwise should probably put a method that throws NSME
        result->obj_at_put(i, NULL);
      } else {
        oop m;
        if (want_constructor) {
+         assert(method->is_object_constructor() ||
+                method->is_static_init_factory(), "must be");
          m = Reflection::new_constructor(method, CHECK_NULL);
        } else {
          m = Reflection::new_method(method, false, CHECK_NULL);
        }
        result->obj_at_put(i, m);

@@ -2108,14 +2140,14 @@
    methodHandle m (THREAD, k->find_method(name, sig));
    if (m.is_null()) {
      THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
    }
    oop method;
-   if (!m->is_initializer() || m->is_static()) {
-     method = Reflection::new_method(m, true, CHECK_NULL);
-   } else {
+   if (m->is_object_constructor() || m->is_static_init_factory()) {
      method = Reflection::new_constructor(m, CHECK_NULL);
+   } else {
+     method = Reflection::new_method(m, true, CHECK_NULL);
    }
    return JNIHandles::make_local(THREAD, method);
  }
  
  JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index))

@@ -2382,10 +2414,47 @@
    JvmtiVMObjectAllocEventCollector oam;
    oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL);
    return JNIHandles::make_local(THREAD, asd);
  JVM_END
  
+ // Arrays support /////////////////////////////////////////////////////////////
+ 
+ JVM_ENTRY(jboolean, JVM_ArrayIsAccessAtomic(JNIEnv *env, jclass unused, jobject array))
+   oop o = JNIHandles::resolve(array);
+   Klass* k = o->klass();
+   if ((o == NULL) || (!k->is_array_klass())) {
+     THROW_0(vmSymbols::java_lang_IllegalArgumentException());
+   }
+   return ArrayKlass::cast(k)->element_access_is_atomic();
+ JVM_END
+ 
+ JVM_ENTRY(jobject, JVM_ArrayEnsureAccessAtomic(JNIEnv *env, jclass unused, jobject array))
+   oop o = JNIHandles::resolve(array);
+   Klass* k = o->klass();
+   if ((o == NULL) || (!k->is_array_klass())) {
+     THROW_0(vmSymbols::java_lang_IllegalArgumentException());
+   }
+   if (k->is_flatArray_klass()) {
+     FlatArrayKlass* vk = FlatArrayKlass::cast(k);
+     if (!vk->element_access_is_atomic()) {
+       /**
+        * Need to decide how to implement:
+        *
+        * 1) Change to objArrayOop layout, therefore oop->klass() differs so
+        * then "<atomic>[Qfoo;" klass needs to subclass "[Qfoo;" to pass through
+        * "checkcast" & "instanceof"
+        *
+        * 2) Use extra header in the flatArrayOop to flag atomicity required and
+        * possibly per instance lock structure. Said info, could be placed in
+        * "trailer" rather than disturb the current arrayOop
+        */
+       Unimplemented();
+     }
+   }
+   return array;
+ JVM_END
+ 
  // Verification ////////////////////////////////////////////////////////////////////////////////
  
  // Reflection for the verifier /////////////////////////////////////////////////////////////////
  
  // RedefineClasses support: bug 6214132 caused verification to fail.

@@ -2544,11 +2613,11 @@
  JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
    ResourceMark rm(THREAD);
    Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
    k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
    Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
-   return method->name() == vmSymbols::object_initializer_name();
+   return method->is_object_constructor();
  JVM_END
  
  
  JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
    ResourceMark rm(THREAD);

@@ -3480,11 +3549,11 @@
  JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
    Handle method_handle;
    if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
      method_handle = Handle(THREAD, JNIHandles::resolve(method));
      Handle receiver(THREAD, JNIHandles::resolve(obj));
-     objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
+     objArrayHandle args = oopFactory::ensure_objArray(JNIHandles::resolve(args0), CHECK_NULL);
      oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
      jobject res = JNIHandles::make_local(THREAD, result);
      if (JvmtiExport::should_post_vm_object_alloc()) {
        oop ret_type = java_lang_reflect_Method::return_type(method_handle());
        assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!");

@@ -3500,12 +3569,12 @@
    }
  JVM_END
  
  
  JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
+   objArrayHandle args = oopFactory::ensure_objArray(JNIHandles::resolve(args0), CHECK_NULL);
    oop constructor_mirror = JNIHandles::resolve(c);
-   objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
    oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
    jobject res = JNIHandles::make_local(THREAD, result);
    if (JvmtiExport::should_post_vm_object_alloc()) {
      JvmtiExport::post_vm_object_alloc(thread, result);
    }
< prev index next >