static S heapWalker_stringValue(Instance obj) { if (obj == null) null; if (!"java.lang.String".equals(obj.getJavaClass().getName())) throw new IllegalArgumentException("Is not a string: " + obj.getInstanceId() + " (" + obj.getJavaClass().getName() + ")"); int UTF16 = 1; Bool COMPACT_STRINGS = cast obj.getJavaClass().getValueOfStaticField("COMPACT_STRINGS"); if (COMPACT_STRINGS == null) ret HeapWalker.stringValue(obj); // We're pre Java 9 O valueInstance = obj.getValueOfField("value"); PrimitiveArrayInstance chars = cast valueInstance; byte coderField = cast obj.getValueOfField("coder"); byte coder = COMPACT_STRINGS ? coderField : (byte) UTF16; int len = chars.getLength() >> coder; char[] text = new char[len]; L values = (L) chars.getValues(); if (coder == UTF16) for (int i = 0; i < text.length; i++) text[i] = values.get(i).charAt(0); else for (int i = 0; i < text.length; i++) text[i] = (char) Int.parseInt(values.get(i)); ret new String(text); }