10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.nashorn.internal.runtime;
27
28 import java.io.Serializable;
29 import java.util.Arrays;
30 import java.util.Map;
31
32 /**
33 * Class representing a persistent compiled script.
34 */
35 public final class StoredScript implements Serializable {
36
37 /** Compilation id */
38 private final int compilationId;
39
40 /** Main class name. */
41 private final String mainClassName;
42
43 /** Map of class names to class bytes. */
44 private final Map<String, byte[]> classBytes;
45
46 /** Constants array. */
47 private final Object[] constants;
48
49 /** Function initializers */
66 this.initializers = initializers;
67 }
68
69 public int getCompilationId() {
70 return compilationId;
71 }
72
73 /**
74 * Returns the main class name.
75 * @return the main class name
76 */
77 public String getMainClassName() {
78 return mainClassName;
79 }
80
81 /**
82 * Returns a map of class names to class bytes.
83 * @return map of class bytes
84 */
85 public Map<String, byte[]> getClassBytes() {
86 return classBytes;
87 }
88
89 /**
90 * Returns the constants array.
91 * @return constants array
92 */
93 public Object[] getConstants() {
94 return constants;
95 }
96
97 Map<Integer, FunctionInitializer> getInitializers() {
98 return initializers;
99 }
100
101 @Override
102 public int hashCode() {
103 int hash = mainClassName.hashCode();
104 hash = 31 * hash + classBytes.hashCode();
105 hash = 31 * hash + Arrays.hashCode(constants);
106 return hash;
107 }
108
109 @Override
110 public boolean equals(final Object obj) {
111 if (obj == this) {
112 return true;
113 }
114 if (!(obj instanceof StoredScript)) {
115 return false;
116 }
117
118 final StoredScript cs = (StoredScript) obj;
|
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.nashorn.internal.runtime;
27
28 import java.io.Serializable;
29 import java.util.Arrays;
30 import java.util.LinkedHashMap;
31 import java.util.Map;
32
33 /**
34 * Class representing a persistent compiled script.
35 */
36 public final class StoredScript implements Serializable {
37
38 /** Compilation id */
39 private final int compilationId;
40
41 /** Main class name. */
42 private final String mainClassName;
43
44 /** Map of class names to class bytes. */
45 private final Map<String, byte[]> classBytes;
46
47 /** Constants array. */
48 private final Object[] constants;
49
50 /** Function initializers */
67 this.initializers = initializers;
68 }
69
70 public int getCompilationId() {
71 return compilationId;
72 }
73
74 /**
75 * Returns the main class name.
76 * @return the main class name
77 */
78 public String getMainClassName() {
79 return mainClassName;
80 }
81
82 /**
83 * Returns a map of class names to class bytes.
84 * @return map of class bytes
85 */
86 public Map<String, byte[]> getClassBytes() {
87 final Map<String, byte[]> clonedMap = new LinkedHashMap<>();
88 for (final Map.Entry<String, byte[]> entry : classBytes.entrySet()) {
89 clonedMap.put(entry.getKey(), entry.getValue().clone());
90 }
91 return clonedMap;
92 }
93
94 /**
95 * Returns the constants array.
96 * @return constants array
97 */
98 public Object[] getConstants() {
99 return constants.clone();
100 }
101
102 /**
103 * Returns the function initializers map.
104 * @return The initializers map.
105 */
106 public Map<Integer, FunctionInitializer> getInitializers() {
107 final Map<Integer, FunctionInitializer> clonedMap = new LinkedHashMap<>();
108 for (final Map.Entry<Integer, FunctionInitializer> entry : initializers.entrySet()) {
109 clonedMap.put(entry.getKey(), new FunctionInitializer(entry.getValue()));
110 }
111 return clonedMap;
112 }
113
114 @Override
115 public int hashCode() {
116 int hash = mainClassName.hashCode();
117 hash = 31 * hash + classBytes.hashCode();
118 hash = 31 * hash + Arrays.hashCode(constants);
119 return hash;
120 }
121
122 @Override
123 public boolean equals(final Object obj) {
124 if (obj == this) {
125 return true;
126 }
127 if (!(obj instanceof StoredScript)) {
128 return false;
129 }
130
131 final StoredScript cs = (StoredScript) obj;
|