static O quickExport(O o, O dest) ctex { ret quickExport_impl(o, dest, new IdentityHashMap); } static O quickExport_impl(O o, O dest, IdentityHashMap seen) ctex { if (o == null || o instanceof String || o instanceof Number) return o; O oo = seen.get(o); if (oo != null) ret oo; if (o instanceof O[]) { O[] l = (O[]) o; O[] destO = new O[l.length]; seen.put(o, destO); for (int i = 0; i < l.length; i++) destO[i] = quickExport_impl(l[i], dest, seen); ret destO; } if (o instanceof List) { List l = cast o; List destO = new ArrayList(l.size()); seen.put(o, destO); for (int i = 0; i < l.size(); i++) destO.add(quickExport_impl(l.get(i), dest, seen)); return destO; } if (o instanceof Map) { Map m = cast o; Map destO = new HashMap(); seen.put(o, destO); for (Object e : ((Map) o).entrySet()) destO.put( quickExport_impl(((Map.Entry) e).getKey(), dest, seen), quickExport_impl(((Map.Entry) e).getValue(), dest, seen)); return destO; } S className = o.getClass().getName(); if (className.startsWith("main$") && !isAnonymousClassName(className)) { Class destClass = getClass(dest, className); if (destClass == null) ret o; // Class not found in target realm, keep object as is //print(o.getClass() + " => " + destClass); if (o.getClass() == destClass) return o; // no export necessary // actually make a new object, copy fields O destO = nuObject(destClass); seen.put(o, destO); Class c = o.getClass(); while (c != O.class) { Field[] fields = c.getDeclaredFields(); for (Field field : fields) { if ((field.getModifiers() & Modifier.STATIC) != 0) continue; field.setAccessible(true); Object value = field.get(o); setOpt(destO, field.getName(), quickExport_impl(value, dest, seen)); } c = c.getSuperclass(); } return destO; } // assume it's a shared library object ret o; }