# HG changeset patch # User Michael Van De Vanter # Date 1425603492 28800 # Node ID ef30b231865806403c77a683c749931e4824c41a # Parent 32b4b06b6fac55939e943f621acbf954e66ce411 Truffle/Instrumentation: the Visualizer for language-specific values now has a "trim" option to limit result size. diff -r 32b4b06b6fac -r ef30b2318658 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Visualizer.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Visualizer.java Wed Mar 04 16:38:36 2015 -0800 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/Visualizer.java Thu Mar 05 16:58:12 2015 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -60,9 +60,12 @@ String displayCallTargetName(CallTarget callTarget); /** - * Converts a value in the guest language to a display string. + * Converts a value in the guest language to a display string. If + * + * @param trim if {@code > 0}, them limit size of String to either the value of trim or the + * number of characters in the first line, whichever is lower. */ - String displayValue(ExecutionContext context, Object value); + String displayValue(ExecutionContext context, Object value, int trim); /** * Converts a slot identifier in the guest language to a display string. diff -r 32b4b06b6fac -r ef30b2318658 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/DefaultVisualizer.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/DefaultVisualizer.java Wed Mar 04 16:38:36 2015 -0800 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/DefaultVisualizer.java Thu Mar 05 16:58:12 2015 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -70,12 +70,34 @@ return callTarget.toString(); } - public String displayValue(ExecutionContext context, Object value) { - return value.toString(); + public String displayValue(ExecutionContext context, Object value, int trim) { + return trim(value.toString(), trim); } public String displayIdentifier(FrameSlot slot) { return slot.getIdentifier().toString(); } + /** + * Trims text if {@code trim > 0} to the shorter of {@code trim} or the length of the first line + * of test. Identity if {@code trim <= 0}. + */ + protected String trim(String text, int trim) { + if (trim == 0) { + return text; + } + final String[] lines = text.split("\n"); + String result = lines[0]; + if (lines.length == 1) { + if (result.length() <= trim) { + return result; + } + if (trim <= 3) { + return result.substring(0, Math.min(result.length() - 1, trim - 1)); + } else { + return result.substring(0, trim - 4) + "..."; + } + } + return (result.length() < trim - 3 ? result : result.substring(0, trim - 4)) + "..."; + } } diff -r 32b4b06b6fac -r ef30b2318658 graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLDefaultVisualizer.java --- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLDefaultVisualizer.java Wed Mar 04 16:38:36 2015 -0800 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/instrument/SLDefaultVisualizer.java Thu Mar 05 16:58:12 2015 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -73,11 +73,11 @@ } @Override - public String displayValue(ExecutionContext context, Object value) { + public String displayValue(ExecutionContext context, Object value, int trim) { if (value == SLNull.SINGLETON) { return "null"; } - return value.toString(); + return trim(value.toString(), trim); } @Override