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