< prev index next >

test/hotspot/jtreg/runtime/ErrorHandling/MachCodeFramesInErrorFile.java

Print this page

137         }
138         String hsErr = Files.readString(hsErrPath);
139         if (System.getenv("DEBUG") != null) {
140             System.err.println(hsErr);
141         }
142         Set<String> frames = new HashSet<>();
143         extractFrames(hsErr, frames, true);
144         if (!crashInJava) {
145             // A crash in native will have Java frames in the hs-err log
146             // as there is a Java frame anchor on the stack.
147             extractFrames(hsErr, frames, false);
148         }
149         int compiledJavaFrames = (int) frames.stream().filter(f -> f.startsWith("J ")).count();
150 
151         Matcher matcherDisasm = Pattern.compile("\\[Disassembly\\].*\\[/Disassembly\\]", Pattern.DOTALL).matcher(hsErr);
152         if (matcherDisasm.find()) {
153             // Real disassembly is present, no MachCode is expected.
154             return;
155         }
156 
157         Matcher matcher = Pattern.compile("\\[MachCode\\]\\s*\\[Verified Entry Point\\]\\s*  # \\{method\\} \\{[^}]*\\} '([^']+)' '([^']+)' in '([^']+)'", Pattern.DOTALL).matcher(hsErr);
158         List<String> machCodeHeaders = matcher.results().map(mr -> String.format("'%s' '%s' in '%s'", mr.group(1), mr.group(2), mr.group(3))).collect(Collectors.toList());
159         int minExpectedMachCodeSections = Math.max(1, compiledJavaFrames);
160         if (machCodeHeaders.size() < minExpectedMachCodeSections) {
161             Asserts.fail(machCodeHeaders.size() + " < " + minExpectedMachCodeSections);
162         }
163     }
164 
165     /**
166      * Extracts the lines in {@code hsErr} below the line starting with
167      * "Native frames:" or "Java frames:" up to the next blank line
168      * and adds them to {@code frames}.
169      */
170     private static void extractFrames(String hsErr, Set<String> frames, boolean nativeStack) {
171         String marker = (nativeStack ? "Native" : "Java") + " frames: ";
172         boolean seenMarker = false;
173         for (String line : hsErr.split(System.lineSeparator())) {
174             if (line.startsWith(marker)) {
175                 seenMarker = true;
176             } else if (seenMarker) {
177                 if (line.trim().isEmpty()) {

137         }
138         String hsErr = Files.readString(hsErrPath);
139         if (System.getenv("DEBUG") != null) {
140             System.err.println(hsErr);
141         }
142         Set<String> frames = new HashSet<>();
143         extractFrames(hsErr, frames, true);
144         if (!crashInJava) {
145             // A crash in native will have Java frames in the hs-err log
146             // as there is a Java frame anchor on the stack.
147             extractFrames(hsErr, frames, false);
148         }
149         int compiledJavaFrames = (int) frames.stream().filter(f -> f.startsWith("J ")).count();
150 
151         Matcher matcherDisasm = Pattern.compile("\\[Disassembly\\].*\\[/Disassembly\\]", Pattern.DOTALL).matcher(hsErr);
152         if (matcherDisasm.find()) {
153             // Real disassembly is present, no MachCode is expected.
154             return;
155         }
156 
157         Matcher matcher = Pattern.compile("\\[MachCode\\]\\s[^{]+\\{method\\} \\{[^}]*\\} '([^']+)' '([^']+)' in '([^']+)'", Pattern.DOTALL).matcher(hsErr);
158         List<String> machCodeHeaders = matcher.results().map(mr -> String.format("'%s' '%s' in '%s'", mr.group(1), mr.group(2), mr.group(3))).collect(Collectors.toList());
159         int minExpectedMachCodeSections = Math.max(1, compiledJavaFrames);
160         if (machCodeHeaders.size() < minExpectedMachCodeSections) {
161             Asserts.fail(machCodeHeaders.size() + " < " + minExpectedMachCodeSections);
162         }
163     }
164 
165     /**
166      * Extracts the lines in {@code hsErr} below the line starting with
167      * "Native frames:" or "Java frames:" up to the next blank line
168      * and adds them to {@code frames}.
169      */
170     private static void extractFrames(String hsErr, Set<String> frames, boolean nativeStack) {
171         String marker = (nativeStack ? "Native" : "Java") + " frames: ";
172         boolean seenMarker = false;
173         for (String line : hsErr.split(System.lineSeparator())) {
174             if (line.startsWith(marker)) {
175                 seenMarker = true;
176             } else if (seenMarker) {
177                 if (line.trim().isEmpty()) {
< prev index next >