Mercurial > hg > truffle
comparison truffle/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/vm/ImplicitExplicitExportTest.java @ 22183:1421041175a7
Adding dispose() and TruffleLanguage.disposeContext to allow user request and languages explicitly free the resources
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Mon, 21 Sep 2015 14:05:33 +0200 |
parents | dc83cc1f94f2 |
children | 6380c7de0159 |
comparison
equal
deleted
inserted
replaced
22167:0480c4873a4a | 22183:1421041175a7 |
---|---|
34 import com.oracle.truffle.api.vm.TruffleVM; | 34 import com.oracle.truffle.api.vm.TruffleVM; |
35 import java.io.IOException; | 35 import java.io.IOException; |
36 import java.io.Reader; | 36 import java.io.Reader; |
37 import java.util.Enumeration; | 37 import java.util.Enumeration; |
38 import java.util.HashMap; | 38 import java.util.HashMap; |
39 import java.util.HashSet; | |
39 import java.util.Map; | 40 import java.util.Map; |
40 import java.util.Properties; | 41 import java.util.Properties; |
42 import java.util.Set; | |
41 import java.util.concurrent.Executors; | 43 import java.util.concurrent.Executors; |
42 import org.junit.After; | 44 import org.junit.After; |
43 import static org.junit.Assert.assertEquals; | 45 import static org.junit.Assert.assertEquals; |
44 import static org.junit.Assert.assertNotEquals; | 46 import static org.junit.Assert.assertNotEquals; |
45 import static org.junit.Assert.assertTrue; | 47 import static org.junit.Assert.assertTrue; |
121 assertEquals("Explicit import from L2 is used", "43", ret); | 123 assertEquals("Explicit import from L2 is used", "43", ret); |
122 assertEquals("Global symbol is also 43", "43", vm.findGlobalSymbol("ahoj").invoke(null).get()); | 124 assertEquals("Global symbol is also 43", "43", vm.findGlobalSymbol("ahoj").invoke(null).get()); |
123 } | 125 } |
124 | 126 |
125 private static final class Ctx { | 127 private static final class Ctx { |
128 static final Set<Ctx> disposed = new HashSet<>(); | |
129 | |
126 final Map<String, String> explicit = new HashMap<>(); | 130 final Map<String, String> explicit = new HashMap<>(); |
127 final Map<String, String> implicit = new HashMap<>(); | 131 final Map<String, String> implicit = new HashMap<>(); |
128 final Env env; | 132 final Env env; |
129 | 133 |
130 public Ctx(Env env) { | 134 public Ctx(Env env) { |
131 this.env = env; | 135 this.env = env; |
132 } | 136 } |
137 | |
138 void dispose() { | |
139 disposed.add(this); | |
140 } | |
133 } | 141 } |
134 | 142 |
135 private abstract static class AbstractExportImportLanguage extends TruffleLanguage<Ctx> { | 143 private abstract static class AbstractExportImportLanguage extends TruffleLanguage<Ctx> { |
136 | 144 |
137 @Override | 145 @Override |
138 protected Ctx createContext(Env env) { | 146 protected Ctx createContext(Env env) { |
139 if (mainThread != null) { | 147 if (mainThread != null) { |
140 assertNotEquals("Should run asynchronously", Thread.currentThread(), mainThread); | 148 assertNotEquals("Should run asynchronously", Thread.currentThread(), mainThread); |
141 } | 149 } |
142 return new Ctx(env); | 150 return new Ctx(env); |
151 } | |
152 | |
153 @Override | |
154 protected void disposeContext(Ctx context) { | |
155 context.dispose(); | |
143 } | 156 } |
144 | 157 |
145 @Override | 158 @Override |
146 protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException { | 159 protected CallTarget parse(Source code, Node context, String... argumentNames) throws IOException { |
147 if (code.getCode().startsWith("parse=")) { | 160 if (code.getCode().startsWith("parse=")) { |