| 173 | // inc increments the reference count of a Java object when it |
| 174 | // is sent to Go. inc returns the refnum for the object. |
| 175 | synchronized int inc(Object o) { |
| 176 | if (o == null) { |
| 177 | return NULL_REFNUM; |
| 178 | } |
| 179 | if (o instanceof Proxy) { |
| 180 | return ((Proxy)o).incRefnum(); |
| 181 | } |
| 182 | Integer refnumObj = javaRefs.get(o); |
| 183 | if (refnumObj == null) { |
| 184 | if (next == Integer.MAX_VALUE) { |
| 185 | throw new RuntimeException("createRef overflow for " + o); |
| 186 | } |
| 187 | refnumObj = next++; |
| 188 | javaRefs.put(o, refnumObj); |
| 189 | } |
| 190 | int refnum = refnumObj; |
| 191 | Ref ref = javaObjs.get(refnum); |
| 192 | if (ref == null) { |
| 193 | ref = new Ref(refnum, o); |
| 194 | javaObjs.put(refnum, ref); |
| 195 | } |
| 196 | ref.inc(); |
| 197 | return refnum; |
| 198 | } |
| 199 | |
| 200 | synchronized void incRefnum(int refnum) { |
| 201 | Ref ref = javaObjs.get(refnum); |