annotate c1x4hotspotsrc/HotSpotVM/src/com/sun/hotspot/c1x/server/ReplacingStreams.java @ 2295:160aacf936ad

removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
author Lukas Stadler <lukas.stadler@jku.at>
date Tue, 12 Apr 2011 16:58:56 +0200
parents 8c426c2891c8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2285
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
1 /*
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
2 * Copyright (c) 2011 Sun Microsystems, Inc. All rights reserved.
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
3 *
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
4 * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
5 * that is described in this document. In particular, and without limitation, these intellectual property
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
6 * rights may include one or more of the U.S. patents listed at http://www.sun.com/patents and one or
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
7 * more additional patents or pending patent applications in the U.S. and in other countries.
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
8 *
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
9 * U.S. Government Rights - Commercial software. Government users are subject to the Sun
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
10 * Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
11 * supplements.
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
12 *
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
13 * Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and Solaris are trademarks or
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
14 * registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
15 * are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
16 * U.S. and other countries.
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
17 *
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
18 * UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
19 * Company, Ltd.
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
20 */
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
21 package com.sun.hotspot.c1x.server;
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
22
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
23 import java.io.*;
2288
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
24 import java.lang.reflect.*;
2285
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
25 import java.util.*;
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
26
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
27 import com.sun.cri.ci.*;
2288
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
28 import com.sun.hotspot.c1x.*;
2285
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
29 import com.sun.hotspot.c1x.Compiler;
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
30
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
31 public class ReplacingStreams {
2288
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
32
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
33 private IdentityHashMap<Object, Placeholder> objectMap = new IdentityHashMap<Object, Placeholder>();
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
34 private ArrayList<Object> objectList = new ArrayList<Object>();
2285
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
35
2288
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
36 private ReplacingOutputStream output;
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
37 private ReplacingInputStream input;
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
38
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
39 private InvocationSocket invocation;
2285
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
40
2288
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
41 public ReplacingStreams(OutputStream outputStream, InputStream inputStream) throws IOException {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
42 output = new ReplacingOutputStream(new BufferedOutputStream(outputStream));
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
43 // required, because creating an ObjectOutputStream writes a header, but doesn't flush the stream
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
44 output.flush();
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
45 input = new ReplacingInputStream(new BufferedInputStream(inputStream));
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
46 invocation = new InvocationSocket(output, input);
2285
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
47
2288
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
48 addStaticObject(CiValue.IllegalValue);
2295
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
49 addStaticObject(HotSpotProxy.DUMMY_CONSTANT_OBJ);
2285
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
50 }
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
51
2288
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
52 public void setInvocationSocket(InvocationSocket invocation) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
53 this.invocation = invocation;
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
54 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
55
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
56 public ReplacingOutputStream getOutput() {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
57 return output;
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
58 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
59
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
60 public ReplacingInputStream getInput() {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
61 return input;
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
62 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
63
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
64 public InvocationSocket getInvocation() {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
65 return invocation;
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
66 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
67
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
68 private void addStaticObject(Object obj) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
69 int id = objectList.size();
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
70 objectList.add(obj);
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
71 objectMap.put(obj, new Placeholder(id));
2285
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
72 }
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
73
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
74 public static class Placeholder implements Serializable {
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
75
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
76 public final int id;
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
77
2288
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
78 public Placeholder(int id) {
2285
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
79 this.id = id;
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
80 }
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
81
2288
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
82 @Override
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
83 public String toString() {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
84 return "#<" + id + ">";
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
85 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
86 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
87
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
88 public static class NewRemoteCallPlaceholder implements Serializable {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
89
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
90 public final Class<?>[] interfaces;
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
91
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
92 public NewRemoteCallPlaceholder(Class<?>[] interfaces) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
93 this.interfaces = interfaces;
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
94 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
95 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
96
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
97 public static class NewDummyPlaceholder implements Serializable {
2285
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
98 }
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
99
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
100 /**
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
101 * Replaces certain cir objects that cannot easily be made Serializable.
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
102 */
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
103 public class ReplacingInputStream extends ObjectInputStream {
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
104
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
105 private Compiler compiler;
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
106
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
107 public ReplacingInputStream(InputStream in) throws IOException {
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
108 super(in);
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
109 enableResolveObject(true);
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
110 }
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
111
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
112 public void setCompiler(Compiler compiler) {
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
113 this.compiler = compiler;
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
114 }
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
115
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
116 @Override
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
117 protected Object resolveObject(Object obj) throws IOException {
2288
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
118 // see ReplacingInputStream.replaceObject for details on when these types of objects are created
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
119
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
120 if (obj instanceof Placeholder) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
121 Placeholder placeholder = (Placeholder) obj;
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
122 obj = objectList.get(placeholder.id);
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
123 return obj;
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
124 }
2285
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
125
2288
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
126 if (obj instanceof NewRemoteCallPlaceholder) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
127 NewRemoteCallPlaceholder newPlaceholder = (NewRemoteCallPlaceholder) obj;
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
128 Placeholder placeholder = new Placeholder(objectList.size());
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
129 obj = Proxy.newProxyInstance(getClass().getClassLoader(), newPlaceholder.interfaces, invocation.new Handler(placeholder));
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
130 objectMap.put(obj, placeholder);
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
131 objectList.add(obj);
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
132 return obj;
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
133 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
134
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
135 if (obj instanceof NewDummyPlaceholder) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
136 obj = new Placeholder(objectList.size());
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
137 objectMap.put(obj, (Placeholder) obj);
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
138 objectList.add(obj);
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
139 return obj;
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
140 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
141
2285
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
142 return obj;
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
143 }
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
144 }
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
145
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
146 /**
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
147 * Replaces certain cir objects that cannot easily be made Serializable.
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
148 */
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
149 public class ReplacingOutputStream extends ObjectOutputStream {
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
150
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
151 public ReplacingOutputStream(OutputStream out) throws IOException {
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
152 super(out);
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
153 enableReplaceObject(true);
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
154 }
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
155
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
156 @Override
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
157 protected Object replaceObject(Object obj) throws IOException {
2288
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
158 // is the object a known instance?
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
159 Placeholder placeholder = objectMap.get(obj);
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
160 if (placeholder != null) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
161 return placeholder;
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
162 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
163
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
164 // is the object an instance of a class that will always be executed remotely?
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
165 if (obj instanceof Remote) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
166 return createRemoteCallPlaceholder(obj);
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
167 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
168
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
169 // is the object a constant of object type?
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
170 if (obj.getClass() == CiConstant.class) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
171 CiConstant constant = (CiConstant) obj;
2295
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
172 if (constant.kind != CiKind.Object) {
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
173 return obj;
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
174 }
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
175 Object contents = constant.asObject();
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
176 if (contents == null) {
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
177 return obj;
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
178 }
2288
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
179 // don't replace if the object already is a placeholder
2295
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
180 if (contents instanceof Placeholder || contents instanceof Long) {
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
181 return obj;
2288
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
182 }
2295
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
183 placeholder = objectMap.get(contents);
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
184 if (placeholder != null) {
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
185 return CiConstant.forObject(placeholder);
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
186 }
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
187 if (contents instanceof Remote) {
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
188 return CiConstant.forObject(createRemoteCallPlaceholder(contents));
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
189 }
160aacf936ad removed last instances of RiType.javaClass, small changes to InvocationSocket and ReplacingStreams to make remote compilation work
Lukas Stadler <lukas.stadler@jku.at>
parents: 2288
diff changeset
190 return CiConstant.forObject(createDummyPlaceholder(contents));
2285
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
191 }
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
192 return obj;
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
193 }
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
194 }
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
195
2288
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
196 public static Class<?>[] getAllInterfaces(Class<?> clazz) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
197 HashSet<Class< ? >> interfaces = new HashSet<Class<?>>();
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
198 getAllInterfaces(clazz, interfaces);
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
199 return interfaces.toArray(new Class<?>[interfaces.size()]);
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
200 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
201
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
202 private static void getAllInterfaces(Class<?> clazz, HashSet<Class<?>> interfaces) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
203 for (Class< ? > iface : clazz.getInterfaces()) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
204 if (!interfaces.contains(iface)) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
205 interfaces.add(iface);
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
206 getAllInterfaces(iface, interfaces);
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
207 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
208 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
209 if (clazz.getSuperclass() != null) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
210 getAllInterfaces(clazz.getSuperclass(), interfaces);
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
211 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
212 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
213
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
214 private Object createRemoteCallPlaceholder(Object obj) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
215 // collect all interfaces that this object's class implements (proxies only support interfaces)
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
216 objectMap.put(obj, new Placeholder(objectList.size()));
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
217 objectList.add(obj);
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
218 return new NewRemoteCallPlaceholder(getAllInterfaces(obj.getClass()));
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
219 }
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
220
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
221 public Object createDummyPlaceholder(Object obj) {
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
222 objectMap.put(obj, new Placeholder(objectList.size()));
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
223 objectList.add(obj);
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
224 return new NewDummyPlaceholder();
8c426c2891c8 client/server: new interface Remote marks classes that should not be serialized, but called remotely
Lukas Stadler <lukas.stadler@jku.at>
parents: 2285
diff changeset
225 }
2285
762de4b26788 turn Compiler and HotSpotTypeResolved into interfaces
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
226 }