Hi all,
I think that MethodType should be serializable,
it will ease the serialization of user defined classes that act
as method handle references.
The patch is attached.
Rémi
diff --git a/src/share/classes/java/dyn/MethodType.java
b/src/share/classes/java/dyn/MethodType.java
--- a/src/share/classes/java/dyn/MethodType.java
+++ b/src/share/classes/java/dyn/MethodType.java
@@ -25,6 +25,9 @@
package java.dyn;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -48,7 +51,9 @@
* @author John Rose, JSR 292 EG
*/
public final
-class MethodType {
+class MethodType implements Serializable {
+ private static final long serialVersionUID = -1060957473313665492L;
+
private final Class<?> rtype;
private final Class<?>[] ptypes;
private MethodTypeForm form; // erased form, plus cached data about
primitives
@@ -192,7 +197,7 @@
* @param trusted whether the ptypes can be used without cloning
* @return the unique method type of the desired structure
*/
- private static
+ static
MethodType makeImpl(Class<?> rtype, Class<?>[] ptypes, boolean trusted) {
if (ptypes == null || ptypes.length == 0) {
ptypes = NO_PTYPES; trusted = true;
@@ -224,6 +229,37 @@
return makeImpl(rtype, ptypes, true);
}
+ private Object writeReplace() {
+ return new SerializationProxy(rtype, ptypes);
+ }
+
+ private void readObject(ObjectInputStream stream)
+ throws InvalidObjectException {
+ throw new InvalidObjectException("a method type must be deserialized
with a proxy");
+ }
+
+ private void readObjectNoData() throws InvalidObjectException {
+ throw new InvalidObjectException("a method type must be deserialized
with a proxy");
+ }
+
+ // Proxy used to serialize/deserialize a method type
+ private static class SerializationProxy implements Serializable {
+ private static final long serialVersionUID = -6288402359746142875L;
+
+ private final Class<?> rtype;
+ private final Class<?>[] ptypes;
+
+ SerializationProxy(Class<?> rtype, Class<?>[] ptypes) {
+ this.rtype = rtype;
+ this.ptypes = ptypes;
+ }
+
+ private Object readResolve() {
+ // array shouldn't be trusted because serialization data can be
forged
+ return makeImpl(rtype, ptypes, false);
+ }
+ }
+
private static final MethodType[] objectOnlyTypes = new MethodType[20];
/**
_______________________________________________
mlvm-dev mailing list
[email protected]
http://mail.openjdk.java.net/mailman/listinfo/mlvm-dev