use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.
the class ObjectPreview method createEntryPreview.
private static JSONObject createEntryPreview(DebugValue entry, boolean allowToStringSideEffects, LanguageInfo language, PrintWriter err) {
List<DebugValue> entryArray = entry.getArray();
DebugValue key = entryArray.get(0);
DebugValue value = entryArray.get(1);
// Setup the object with a language-specific value
if (language != null) {
key = key.asInLanguage(language);
value = value.asInLanguage(language);
}
JSONObject json = new JSONObject();
json.put("key", create(key, allowToStringSideEffects, language, err, true));
json.put("value", create(value, allowToStringSideEffects, language, err, true));
return json;
}
use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.
the class ObjectPreview method create.
private static JSONObject create(DebugValue debugValue, TYPE type, SUBTYPE subtype, boolean allowToStringSideEffects, LanguageInfo language, PrintWriter err, boolean isMapEntryKV) {
JSONObject json = new JSONObject();
json.put("type", type.getId());
if (subtype != null) {
json.put("subtype", subtype.getId());
}
boolean isArray = debugValue.isArray();
boolean isMap = debugValue.hasHashEntries();
if (isMapEntryKV) {
String valueStr = RemoteObject.toString(debugValue, allowToStringSideEffects, err);
json.putOpt("description", valueStr);
} else {
DebugValue metaObject = RemoteObject.getMetaObject(debugValue, language, err);
String metaType = null;
if (metaObject != null) {
metaType = RemoteObject.toMetaName(metaObject, err);
if (isArray) {
metaType += "(" + debugValue.getArray().size() + ")";
} else if (isMap) {
metaType += "(" + debugValue.getHashSize() + ")";
}
}
json.putOpt("description", metaType);
}
boolean overflow;
JSONArray properties = new JSONArray();
JSONArray entries = new JSONArray();
if (isArray) {
List<DebugValue> array = debugValue.getArray();
int size = array.size();
overflow = size > OVERFLOW_LIMIT_ARRAY_ELEMENTS;
int n = Math.min(size, OVERFLOW_LIMIT_ARRAY_ELEMENTS);
for (int i = 0; i < n; i++) {
try {
properties.put(createPropertyPreview(array.get(i), allowToStringSideEffects, language, err));
} catch (DebugException ex) {
overflow = true;
break;
}
}
} else if (isMap && !isMapEntryKV) {
DebugValue entriesIter = debugValue.getHashEntriesIterator();
overflow = false;
while (entriesIter.hasIteratorNextElement()) {
DebugValue entry = entriesIter.getIteratorNextElement();
JSONObject entryPreview;
try {
entryPreview = createEntryPreview(entry, allowToStringSideEffects, language, err);
} catch (DebugException ex) {
overflow = true;
break;
}
if (entryPreview != null) {
if (entries.length() == OVERFLOW_LIMIT_PROPERTIES) {
overflow = true;
break;
}
entries.put(entryPreview);
}
}
} else {
Collection<DebugValue> valueProperties = debugValue.getProperties();
if (valueProperties != null) {
Iterator<DebugValue> propertyIterator = valueProperties.iterator();
overflow = false;
while (propertyIterator.hasNext()) {
DebugValue property = propertyIterator.next();
if (!property.isInternal() && !property.hasReadSideEffects() && property.isReadable()) {
if (properties.length() == OVERFLOW_LIMIT_PROPERTIES) {
overflow = true;
break;
}
try {
properties.put(createPropertyPreview(property, allowToStringSideEffects, language, err));
} catch (DebugException ex) {
overflow = true;
break;
}
}
}
} else {
overflow = false;
}
}
json.put("overflow", overflow);
json.put("properties", properties);
if (isMap && !isMapEntryKV) {
json.put("entries", entries);
}
return json;
}
use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.
the class ProfileNode method toJSON.
private JSONObject toJSON() {
JSONObject json = new JSONObject();
json.put("id", id);
json.put("callFrame", callFrame.toJSON());
json.put("hitCount", hitCount);
JSONArray array = new JSONArray();
children.forEach(i -> {
array.put(i.intValue());
});
json.put("children", array);
return json;
}
use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.
the class Scope method createJSON.
private JSONObject createJSON() {
JSONObject json = new JSONObject();
json.put("type", type);
json.put("object", object.toJSON());
json.putOpt("name", name);
if (startLocation != null) {
json.put("startLocation", startLocation.toJSON());
}
if (endLocation != null) {
json.put("endLocation", endLocation.toJSON());
}
return json;
}
use of com.oracle.truffle.tools.utils.json.JSONObject in project graal by oracle.
the class ScriptCoverage method toJSON.
public JSONObject toJSON() {
JSONObject json = new JSONObject();
json.put("scriptId", Integer.toString(scriptId));
json.put("url", url);
json.put("functions", FunctionCoverage.toJSON(functions));
return json;
}
Aggregations