Re: minutes Valhalla EG June 07, 2017

2017-07-19 Thread Daniel Heidinga
Thanks John.
 
Can you expand on why "int.class.isPrimary() == false"?  Does this depend on being able to retroactively make Integer the box of the int.class value type?
 
> +     * Value type mirrors are never primaries; their corresponding
> +     * box reference types are primaries.
 
Is this an MVT statement or a longer term statement?  With the goal of moving away from MVT's box first model, I would have thought eventually the value type would be the primary and the box would be the secondary.  Is that correct?
 
> +     * TBD:An array type returns the primary class
> +     * of its component type.  
 
This is definitely a useful addition!  We have an equivalent VM-level api for this that makes certain kinds of code easier to write.
 
 
> +     *                                  A primitive type returns the
> +     * corresponding wrapper type.
 
Same as above - does this depend on making Integer <--> int a valuetype relationship?
 
> +     * The user is expected to perform relevant interning,
What action should the VM take if the user doesn't perform interning?  Does the VM need to do any validation of the name / userData pair?  Can the same name be used with different data?
 
makeSecondaryClass(Foo.class, "Foo_A", new Object());
makeSecondaryClass(Foo.class, "Foo_A", new Object());
What's the expected behaviour in this case?
 
From a VM perspective, this api returns new j.l.Class objects with different names and userData, but exactly the same bytecodes, methods, & fields?
 
What name is expected to be printed in a stacktrace?  I don't know about Hotspot but in J9, we record PCs when creating the stacktrace and only decode to names when necessary which would print the Foo.class name, not the user-supplied name.
 
--Dan
 
- Original message -From: John Rose To: Daniel Heidinga Cc: Karen Kinnear , valhalla-spec-experts@openjdk.java.netSubject: Re: minutes Valhalla EG June 07, 2017Date: Wed, Jun 21, 2017 11:51 AM On Jun 21, 2017, at 6:55 AM, Daniel Heidinga  wrote:

 
>  AI: John - send out javadoc to EG> derived class := Class.derivedClassFactory(Class mainClass, T userData, String name)
 
In the spirit of the usual "5 min before the meeting" ritual action item panic, I'm trying to review the javadoc for this and can't seem to find it.  Can it be sent again?
 
Apologies; here it is, 10 min before the meeting.
 
diff --git a/src/java.base/share/classes/java/lang/Class.java b/src/java.base/share/classes/java/lang/Class.java
--- a/src/java.base/share/classes/java/lang/Class.java
+++ b/src/java.base/share/classes/java/lang/Class.java
@@ -681,6 +681,65 @@
     public native boolean isPrimitive();
 
     /**
+     * Determines if the specified {@code Class} object is the
+     * primary representative of an underlying class file.
+     * Array and primitive classes are never primaries.
+     * Other reference type constants of the form {@code X.class}
+     * are always primaries.
+     * Value type mirrors are never primaries; their corresponding
+     * box reference types are primaries.
+     *
+     * @return true if and only if this class is the primary
+     * representative of its underlying class file
+     */
+    @HotSpotIntrinsicCandidate
+    public native boolean isPrimary();
+
+    /**
+     * Obtains the primary class corresponding to the specified
+     * {@code Class} object, if this class is a secondary class
+     * derived from a primary class
+     * If this class object is a primary class, it returns the
+     * same class object.
+     * TBD:An array type returns the primary class
+     * of its component type.  A primitive type returns the
+     * corresponding wrapper type.  A value type returns the
+     * primary class of its box type.  A specialized generic
+     * returns the primary class of its template type.
+     * OR, an non-total version:Primitive and array classes
+     * do not have associated primary classes; they return
+     * {@code null} for this query.
+     *
+     * @return the primary representative of the underlying class file
+     */
+    @HotSpotIntrinsicCandidate
+    public native Class getPrimaryClass();
+
+    /**
+     * Creates a new non-primary class for the given primary.
+     * This is an internal factory for non-primary classes.
+     * The user is expected to perform relevant interning,
+     * and manage the type of the user-data component.
+     * @param primary the primary class for the new secondary
+     * @param name arbitrary name string, to be the name of the new secondary
+     * @param userData arbitrary reference to associate with the new secondary
+     * @return a fresh secondary class
+     * @throws IllegalArgumentException if the first argument is not a primary class
+     */
+    /*non-public*/
+    @HotSpotIntrinsicCandidate
+    static native Class makeSecondaryClass(Class primary, String name, Object userData);
+
+    /**
+     * Extract the user-data provided when the given secondary class
+

Re: minutes Valhalla EG June 07, 2017

2017-06-21 Thread John Rose
On Jun 21, 2017, at 8:56 AM, Remi Forax  wrote:
> 
> John,
> Do we agree that this API can also replace the constant pool patching done by 
> unsafe.defineAnonymousClass,
> i.e. that the Object can be any live Object?

This seems close to possible, although I would imagine that a nest-injected
class would usually be a primary class.  That means getUserData would
return non-null for a primary, which goes a little beyond what was envisioned
in that patch.  The userData value would be passed to the nest-injector 
function.

— John



Re: minutes Valhalla EG June 07, 2017

2017-06-21 Thread Remi Forax
John, 
Do we agree that this API can also replace the constant pool patching done by 
unsafe.defineAnonymousClass, 
i.e. that the Object can be any live Object? 

Rémi 

> De: "John Rose" 
> À: "Daniel Heidinga" 
> Cc: valhalla-spec-experts@openjdk.java.net
> Envoyé: Mercredi 21 Juin 2017 17:51:11
> Objet: Re: minutes Valhalla EG June 07, 2017

> On Jun 21, 2017, at 6:55 AM, Daniel Heidinga < daniel_heidi...@ca.ibm.com >
> wrote:

>> > AI: John - send out javadoc to EG
>>> derived class := Class.derivedClassFactory(Class mainClass, T userData, 
>>> String
>> > name)
>> In the spirit of the usual "5 min before the meeting" ritual action item 
>> panic,
>> I'm trying to review the javadoc for this and can't seem to find it. Can it 
>> be
>> sent again?

> Apologies; here it is, 10 min before the meeting.

> diff --git a/src/java.base/share/classes/java/lang/Class.java
> b/src/java.base/share/classes/java/lang/Class.java
> --- a/src/java.base/share/classes/java/lang/Class.java
> +++ b/src/java.base/share/classes/java/lang/Class.java
> @@ -681,6 +681,65 @@
> public native boolean isPrimitive();
> /**
> + * Determines if the specified {@code Class} object is the
> + * primary representative of an underlying class file.
> + * Array and primitive classes are never primaries.
> + * Other reference type constants of the form {@code X.class}
> + * are always primaries.
> + * Value type mirrors are never primaries; their corresponding
> + * box reference types are primaries.
> + *
> + * @return true if and only if this class is the primary
> + * representative of its underlying class file
> + */
> + @HotSpotIntrinsicCandidate
> + public native boolean isPrimary();
> +
> + /**
> + * Obtains the primary class corresponding to the specified
> + * {@code Class} object, if this class is a secondary class
> + * derived from a primary class
> + * If this class object is a primary class, it returns the
> + * same class object.
> + * TBD:An array type returns the primary class
> + * of its component type. A primitive type returns the
> + * corresponding wrapper type. A value type returns the
> + * primary class of its box type. A specialized generic
> + * returns the primary class of its template type.
> + * OR, an non-total version:Primitive and array classes
> + * do not have associated primary classes; they return
> + * {@code null} for this query.
> + *
> + * @return the primary representative of the underlying class file
> + */
> + @HotSpotIntrinsicCandidate
> + public native Class getPrimaryClass();
> +
> + /**
> + * Creates a new non-primary class for the given primary.
> + * This is an internal factory for non-primary classes.
> + * The user is expected to perform relevant interning,
> + * and manage the type of the user-data component.
> + * @param primary the primary class for the new secondary
> + * @param name arbitrary name string, to be the name of the new secondary
> + * @param userData arbitrary reference to associate with the new secondary
> + * @return a fresh secondary class
> + * @throws IllegalArgumentException if the first argument is not a primary
> class
> + */
> + /*non-public*/
> + @HotSpotIntrinsicCandidate
> + static native Class makeSecondaryClass(Class primary, String name,
> Object userData);
> +
> + /**
> + * Extract the user-data provided when the given secondary class
> + * was created by the {@code makeSecondaryClass} factory.
> + * Returns {@code null} if it was not created by that factory.
> + */
> + /*non-public*/
> + @HotSpotIntrinsicCandidate
> + native Object getSecondaryUserData();
> +
> + /**
> * Returns true if this {@code Class} object represents an annotation
> * type. Note that if this method returns true, {@link #isInterface()}
> * would also return true, as all annotation types are also interfaces.


Re: minutes Valhalla EG June 07, 2017

2017-06-21 Thread John Rose
On Jun 21, 2017, at 6:55 AM, Daniel Heidinga  wrote:
> 
> >  AI: John - send out javadoc to EG
> > derived class := Class.derivedClassFactory(Class mainClass, T userData, 
> > String name)
>  
> In the spirit of the usual "5 min before the meeting" ritual action item 
> panic, I'm trying to review the javadoc for this and can't seem to find it.  
> Can it be sent again?
>  

Apologies; here it is, 10 min before the meeting.

diff --git a/src/java.base/share/classes/java/lang/Class.java 
b/src/java.base/share/classes/java/lang/Class.java
--- a/src/java.base/share/classes/java/lang/Class.java
+++ b/src/java.base/share/classes/java/lang/Class.java
@@ -681,6 +681,65 @@
 public native boolean isPrimitive();
 
 /**
+ * Determines if the specified {@code Class} object is the
+ * primary representative of an underlying class file.
+ * Array and primitive classes are never primaries.
+ * Other reference type constants of the form {@code X.class}
+ * are always primaries.
+ * Value type mirrors are never primaries; their corresponding
+ * box reference types are primaries.
+ *
+ * @return true if and only if this class is the primary
+ * representative of its underlying class file
+ */
+@HotSpotIntrinsicCandidate
+public native boolean isPrimary();
+
+/**
+ * Obtains the primary class corresponding to the specified
+ * {@code Class} object, if this class is a secondary class
+ * derived from a primary class
+ * If this class object is a primary class, it returns the
+ * same class object.
+ * TBD:An array type returns the primary class
+ * of its component type.  A primitive type returns the
+ * corresponding wrapper type.  A value type returns the
+ * primary class of its box type.  A specialized generic
+ * returns the primary class of its template type.
+ * OR, an non-total version:Primitive and array classes
+ * do not have associated primary classes; they return
+ * {@code null} for this query.
+ *
+ * @return the primary representative of the underlying class file
+ */
+@HotSpotIntrinsicCandidate
+public native Class getPrimaryClass();
+
+/**
+ * Creates a new non-primary class for the given primary.
+ * This is an internal factory for non-primary classes.
+ * The user is expected to perform relevant interning,
+ * and manage the type of the user-data component.
+ * @param primary the primary class for the new secondary
+ * @param name arbitrary name string, to be the name of the new secondary
+ * @param userData arbitrary reference to associate with the new secondary
+ * @return a fresh secondary class
+ * @throws IllegalArgumentException if the first argument is not a primary 
class
+ */
+/*non-public*/
+@HotSpotIntrinsicCandidate
+static native Class makeSecondaryClass(Class primary, String name, 
Object userData);
+
+/**
+ * Extract the user-data provided when the given secondary class
+ * was created by the {@code makeSecondaryClass} factory.
+ * Returns {@code null} if it was not created by that factory.
+ */
+/*non-public*/
+@HotSpotIntrinsicCandidate
+native Object getSecondaryUserData();
+
+/**
  * Returns true if this {@code Class} object represents an annotation
  * type.  Note that if this method returns true, {@link #isInterface()}
  * would also return true, as all annotation types are also interfaces.




Re: minutes Valhalla EG June 07, 2017

2017-06-21 Thread Karen Kinnear
Dan - 

I can’t find it either. We’ll have to ask John.

thanks,
Karen

> On Jun 21, 2017, at 9:55 AM, Daniel Heidinga  
> wrote:
> 
> >  AI: John - send out javadoc to EG
> > derived class := Class.derivedClassFactory(Class mainClass, T userData, 
> > String name)
>  
> In the spirit of the usual "5 min before the meeting" ritual action item 
> panic, I'm trying to review the javadoc for this and can't seem to find it.  
> Can it be sent again?
>  
> Thanks,
> --Dan
>  
> - Original message -
> From: Karen Kinnear 
> Sent by: "valhalla-spec-experts" 
> 
> To: valhalla-spec-experts@openjdk.java.net
> Cc:
> Subject: minutes Valhalla EG June 07, 2017
> Date: Wed, Jun 7, 2017 4:28 PM
>  
> Valhalla EG Minutes June 07, 2017
>  
> attendees: Bjorn, Dan H, Dan S, John, Vlad, Frederic, Lois, Brian, Maurizio, 
> Karen
>  
> AI ALL:
>   Dan Smith sent an initial draft of a JVMS with experimental support for MVT 
> for review.
>   Feedback in email requested - sooner rather than later please.
> AI ALL:
>   Review embedded proposal for issue 1 - John javadoc to avoid exposing 
> internal derived value type name
>   Review embedded proposal for EA for handling CONSTANT_Class
>  
> Timing note:
>   Value type exploration is following three timeframes:
>  Minimal Value Types Early Access (EA) - goal: ASAP so we can get 
> feedback from initial users
>  Minimal Value Types (MVT)   - goal: w/JDK10 for much broader feedback
>  Valhalla Value Types - "real" vs. shady values - much richer feature set
>   Some of the issues we are exploring - such as type vs. class will need to 
> evolve, so we need
>   to reach decisions on our initial EA stake in the ground ASAP.
>   For that - review of and conclusions to JVMS and other open issues is 
> needed.
>  
> Issue 1: Exposure of mirror and mirror name for the value class
> Bjorn: (please correct any inaccuracies)
>   IBM implementation does NOT expose the value type mirror name
>   ValueType.valueClass is the only way to get the value type mirror
>   getClassName returns the same answer
>   2 java objects, same underlying data
>   no internal derived value type name is exposed
>  
> John: proposal for breaking the link to the secondary mirror
>Model is that there is one primary mirror and multiple secondary mirrors
>Brian: one nominal class and multiple derived classes analogous to a 
> DirectMethodHandle and derived
> MethodHandles
>Later reflection couild add APIs at the java level to get the secondary 
> mirrors
>- has an initial proposal in which you pass in
>head class, user data (e.g. value type descriptor), user-chosen name
>name is not resolvable, doesn't work for findClass, but visible when 
> reflecting
>  
> Dan H: do we need to ensure user name/user data consistent? That has been an 
> issue in related APIs?
> John: no
> Karen: assume we can not use this name to look up a class (forName)? just for 
> reflection to print?
> John: not for lookup
>  
> Maurizio: this could be useful today (i.e. for EA) for a value class
> Issue: Reflection behavior for EA
>Karen: we already agreed reflection will not work - will throw an exception
>Maurizio: it could be actually easier to use John's factory than to throw 
> an exception
>  
> Timing:
>   AI: John - send out javadoc to EG
> derived class := Class.derivedClassFactory(Class mainClass, T userData, 
> String name)
>   All: evaluate proposal both for doability
>also evaluate for timing: EA vs. MVT?
>  
>  
> Issue 2: Constant Pool representation for derived value type (JVMS term: 
> value class)
>  
> Goals:
>   1. cache point for usage - need separate storage for DVT and VCC
>   2. prefer not to do string parsing over and over to get the mode
>   3. verifier ensure type safety without additional eager class loading
>   4. ensure single resolution of underlying value-capable-class
>  (longer-term want single resolution of underlying source classfile)
>   5. allow implementations to support older classfiles
>   6. tool support - make sure this works for a mix of constant pool changes
>  e.g. tools that do not know about new versions still instrument new 
> classfiles
>  - need to make sure these still work as much as possible
>  - so for these folks we need to not change the meaning of CONSTANT_Class
>   7. future - make sure the model works for future derivation from more than 
> one type
>  - e.g. Foo
> 7a. request that for a Parameterized Type: this_class (name and 
> CONSTANT_Class today)
> allows lazy resolution of the list
> (ed. note: need to discuss details of "lazy" here - loading the class 
> file perhaps,
> but instantiating a type from it will need the parameterizations, so far 
> we have
> conceptually recorded the loaded class file under the "head" type, with 
> default/erased
> parameterizations)
>   8. upside opportunity: Constable and pattern matching - helpful if all 
> class objects
>  were 

Re: minutes Valhalla EG June 07, 2017

2017-06-21 Thread Daniel Heidinga
>  AI: John - send out javadoc to EG> derived class := Class.derivedClassFactory(Class mainClass, T userData, String name)
 
In the spirit of the usual "5 min before the meeting" ritual action item panic, I'm trying to review the javadoc for this and can't seem to find it.  Can it be sent again?
 
Thanks,
--Dan
 
- Original message -From: Karen Kinnear Sent by: "valhalla-spec-experts" To: valhalla-spec-experts@openjdk.java.netCc:Subject: minutes Valhalla EG June 07, 2017Date: Wed, Jun 7, 2017 4:28 PM 
Valhalla EG Minutes June 07, 2017
 
attendees: Bjorn, Dan H, Dan S, John, Vlad, Frederic, Lois, Brian, Maurizio, Karen
 
AI ALL:
  Dan Smith sent an initial draft of a JVMS with experimental support for MVT for review.
  Feedback in email requested - sooner rather than later please.
AI ALL:
  Review embedded proposal for issue 1 - John javadoc to avoid exposing internal derived value type name
  Review embedded proposal for EA for handling CONSTANT_Class
 
Timing note:
  Value type exploration is following three timeframes:
     Minimal Value Types Early Access (EA) - goal: ASAP so we can get feedback from initial users
     Minimal Value Types (MVT)   - goal: w/JDK10 for much broader feedback
     Valhalla Value Types - "real" vs. shady values - much richer feature set
  Some of the issues we are exploring - such as type vs. class will need to evolve, so we need
  to reach decisions on our initial EA stake in the ground ASAP.
  For that - review of and conclusions to JVMS and other open issues is needed.
 
Issue 1: Exposure of mirror and mirror name for the value class
Bjorn: (please correct any inaccuracies)
  IBM implementation does NOT expose the value type mirror name
  ValueType.valueClass is the only way to get the value type mirror
  getClassName returns the same answer
  2 java objects, same underlying data
  no internal derived value type name is exposed
 
John: proposal for breaking the link to the secondary mirror
   Model is that there is one primary mirror and multiple secondary mirrors
   Brian: one nominal class and multiple derived classes analogous to a DirectMethodHandle and derived
MethodHandles
   Later reflection couild add APIs at the java level to get the secondary mirrors
   - has an initial proposal in which you pass in
       head class, user data (e.g. value type descriptor), user-chosen name
       name is not resolvable, doesn't work for findClass, but visible when reflecting
 
Dan H: do we need to ensure user name/user data consistent? That has been an issue in related APIs?
John: no
Karen: assume we can not use this name to look up a class (forName)? just for reflection to print?
John: not for lookup
 
Maurizio: this could be useful today (i.e. for EA) for a value class
Issue: Reflection behavior for EA
   Karen: we already agreed reflection will not work - will throw an exception
   Maurizio: it could be actually easier to use John's factory than to throw an exception
 
Timing:
  AI: John - send out javadoc to EG
derived class := Class.derivedClassFactory(Class mainClass, T userData, String name)
  All: evaluate proposal both for doability
       also evaluate for timing: EA vs. MVT?
 
 
Issue 2: Constant Pool representation for derived value type (JVMS term: value class)
 
Goals:
  1. cache point for usage - need separate storage for DVT and VCC
  2. prefer not to do string parsing over and over to get the mode
  3. verifier ensure type safety without additional eager class loading
  4. ensure single resolution of underlying value-capable-class
     (longer-term want single resolution of underlying source classfile)
  5. allow implementations to support older classfiles
  6. tool support - make sure this works for a mix of constant pool changes
     e.g. tools that do not know about new versions still instrument new classfiles
     - need to make sure these still work as much as possible
     - so for these folks we need to not change the meaning of CONSTANT_Class
  7. future - make sure the model works for future derivation from more than one type
     - e.g. Foo
    7a. request that for a Parameterized Type: this_class (name and CONSTANT_Class today)
        allows lazy resolution of the list
    (ed. note: need to discuss details of "lazy" here - loading the class file perhaps,
    but instantiating a type from it will need the parameterizations, so far we have
    conceptually recorded the loaded class file under the "head" type, with default/erased
    parameterizations)
  8. upside opportunity: Constable and pattern matching - helpful if all class objects
     were represented the same way when generating bytecode
     e.g. int.class vs. Integer.class require different handling today
  9. migration: a class should be able to migrate to being a value type
     approach: will require boxing to access, but if you pass for example a boxed value type
     the current client should continue to work
  10. migration: value type to reference?  Open question
 
   11. ed.