annotate truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/nodes/serial/TestSerializerConstantPool.java @ 22157:dc83cc1f94f2

Using fully qualified imports
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 16 Sep 2015 11:33:22 +0200
parents 9c8c0937da41
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12388
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 *
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * accompanied this code).
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 *
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 *
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * questions.
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 */
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 package com.oracle.truffle.api.test.nodes.serial;
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
25 import com.oracle.truffle.api.nodes.serial.SerializerConstantPool;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
26 import com.oracle.truffle.api.nodes.serial.UnsupportedConstantPoolTypeException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
27 import java.util.HashMap;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
28 import java.util.Map;
12388
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
29
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30 class TestSerializerConstantPool implements SerializerConstantPool {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
31
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
32 private final Map<Integer, Object> int2object = new HashMap<>();
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
33 private final Map<Object, Integer> object2int = new HashMap<>();
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
34
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
35 private int index;
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
36
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37 public void setIndex(int index) {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
38 this.index = index;
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
40
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 public int getIndex() {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42 return index;
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
44
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
45 @Override
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 public double getDouble(int cpi) {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
47 return (Double) int2object.get(cpi);
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
48 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
49
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50 @Override
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51 public float getFloat(int cpi) {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52 return (Float) int2object.get(cpi);
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55 @Override
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
56 public Object getObject(Class<?> clazz, int cpi) throws UnsupportedConstantPoolTypeException {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57 return int2object.get(cpi);
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
60 @Override
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
61 public int putDouble(double value) {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
62 return put(value);
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
63 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 public int putFloat(float value) {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66 return put(value);
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
67 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
68
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
69 public int putObject(java.lang.Class<?> clazz, Object value) throws UnsupportedConstantPoolTypeException {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
70 return put(value);
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
71 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
72
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
73 @Override
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
74 public int putClass(Class<?> clazz) {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
75 return put(clazz);
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
76 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
77
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
78 private int put(Object o) {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
79 Integer currentIndex = object2int.get(o);
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
80 if (currentIndex == null) {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
81 int2object.put(index, o);
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
82 object2int.put(o, index);
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83 return index++;
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
84 } else {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 return currentIndex;
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
86 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
87 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
88
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 @Override
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90 public Class<?> getClass(int idx) {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
91 return (Class<?>) int2object.get(idx);
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
92 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
93
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
94 @Override
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
95 public int putInt(int constant) {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
96 return put(constant);
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
97 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
98
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
99 @Override
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
100 public int getInt(int idx) {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
101 return (Integer) int2object.get(idx);
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
102 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
103
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
104 @Override
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
105 public long getLong(int idx) {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
106 return (Long) int2object.get(idx);
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
107 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
108
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
109 @Override
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
110 public int putLong(long value) {
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
111 return put(value);
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
112 }
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
113
96c1d057a5ed Truffle: Added experimental serialization API.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
114 }