Skip to content

Commit a223a84

Browse files
committed
The source loader now uses a URL instead of a TruffleFile to represent at debug source file.
Fixed a potential NPE bug when checking for wasm mime type.
1 parent d2115b8 commit a223a84

File tree

6 files changed

+33
-18
lines changed

6 files changed

+33
-18
lines changed

tools/src/com.oracle.truffle.tools.chromeinspector/src/com/oracle/truffle/tools/chromeinspector/types/Script.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public Source getSourceLoaded() {
6464
}
6565

6666
public boolean hasWasmSource() {
67-
return source.hasBytes() && source.getMimeType().equals("application/wasm");
67+
return source.hasBytes() && "application/wasm".equals(source.getMimeType());
6868
}
6969

7070
public CharSequence getCharacters() {

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/debugging/data/DebugFunction.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
import org.graalvm.wasm.debugging.parser.DebugSourceLoader;
5151
import org.graalvm.wasm.nodes.WasmDataAccess;
5252

53-
import com.oracle.truffle.api.TruffleLanguage;
5453
import com.oracle.truffle.api.frame.MaterializedFrame;
54+
import com.oracle.truffle.api.source.Source;
5555
import com.oracle.truffle.api.source.SourceSection;
5656

5757
/**
@@ -140,7 +140,7 @@ public String language() {
140140

141141
/**
142142
* @return Whether the source section of this function has already been computed.
143-
* @see #computeSourceSection(DebugSourceLoader, TruffleLanguage.Env)
143+
* @see #computeSourceSection(DebugSourceLoader)
144144
*/
145145
public boolean hasSourceSection() {
146146
return sourceSection != null;
@@ -159,9 +159,12 @@ public SourceSection getSourceSection() {
159159
/**
160160
* Computes the source section for the function.
161161
*/
162-
public SourceSection computeSourceSection(DebugSourceLoader sourceLoader, TruffleLanguage.Env environment) {
162+
public SourceSection computeSourceSection(DebugSourceLoader sourceLoader) {
163163
if (sourceSection == null) {
164-
sourceSection = sourceLoader.load(filePath, language, environment).createSection(startLine);
164+
final Source source = sourceLoader.load(filePath, language);
165+
if (source != null) {
166+
sourceSection = source.createSection(startLine);
167+
}
165168
}
166169
return sourceSection;
167170
}

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/debugging/parser/DebugSourceLoader.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@
4141

4242
package org.graalvm.wasm.debugging.parser;
4343

44+
import java.net.MalformedURLException;
4445
import java.nio.file.Path;
4546
import java.util.HashMap;
4647
import java.util.Map;
4748

4849
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
49-
import com.oracle.truffle.api.TruffleFile;
50-
import com.oracle.truffle.api.TruffleLanguage;
5150
import com.oracle.truffle.api.source.Source;
5251

5352
/**
@@ -61,10 +60,9 @@ public class DebugSourceLoader {
6160
*
6261
* @param path the path of the source
6362
* @param language the source language
64-
* @param env Truffle environment used to access source files
6563
*/
6664
@TruffleBoundary
67-
public Source load(Path path, String language, TruffleLanguage.Env env) {
65+
public Source load(Path path, String language) {
6866
if (path == null || language == null) {
6967
return null;
7068
}
@@ -75,8 +73,13 @@ public Source load(Path path, String language, TruffleLanguage.Env env) {
7573
if (cache.containsKey(path)) {
7674
return cache.get(path);
7775
}
78-
final TruffleFile file = env.getInternalTruffleFile(path.toString());
79-
final Source source = Source.newBuilder(language, file).content(Source.CONTENT_NONE).build();
76+
final Source source;
77+
try {
78+
source = Source.newBuilder(language, path.toUri().toURL()).content(Source.CONTENT_NONE).build();
79+
} catch (MalformedURLException | SecurityException e) {
80+
// source not available or not accessible
81+
return null;
82+
}
8083
cache.put(path, source);
8184
return source;
8285
}

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/nodes/WasmFunctionRootNode.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public final SourceSection getSourceSection() {
318318
} else {
319319
final WasmContext context = WasmContext.get(this);
320320
if (context != null) {
321-
sourceSection = debugFunction.computeSourceSection(context.debugSourceLoader(), context.environment());
321+
sourceSection = debugFunction.computeSourceSection(context.debugSourceLoader());
322322
}
323323
}
324324
} else {
@@ -331,4 +331,9 @@ public final SourceSection getSourceSection() {
331331
public final Node[] getCallNodes() {
332332
return functionNode.getCallNodes();
333333
}
334+
335+
@Override
336+
public boolean isInternal() {
337+
return false;
338+
}
334339
}

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/nodes/WasmInstrumentableFunctionNode.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
import com.oracle.truffle.api.library.ExportLibrary;
7171
import com.oracle.truffle.api.library.ExportMessage;
7272
import com.oracle.truffle.api.nodes.Node;
73-
import com.oracle.truffle.api.source.Source;
7473
import com.oracle.truffle.api.source.SourceSection;
7574

7675
/**
@@ -163,7 +162,7 @@ public SourceSection getSourceSection() {
163162
} else {
164163
final WasmContext context = WasmContext.get(this);
165164
if (context != null) {
166-
return debugFunction.computeSourceSection(context.debugSourceLoader(), context.environment());
165+
return debugFunction.computeSourceSection(context.debugSourceLoader());
167166
}
168167
}
169168
}
@@ -185,8 +184,8 @@ public InstrumentableNode materializeInstrumentableNodes(Set<Class<? extends Tag
185184
if (debugFunction == null) {
186185
return this;
187186
}
188-
final Source source = debugFunction.computeSourceSection(context.debugSourceLoader(), context.environment()).getSource();
189-
if (source == null) {
187+
final SourceSection sourceSection = debugFunction.computeSourceSection(context.debugSourceLoader());
188+
if (sourceSection == null) {
190189
return this;
191190
}
192191
final int functionStartOffset = module.functionSourceCodeStartOffset(functionIndex);
@@ -195,7 +194,7 @@ public InstrumentableNode materializeInstrumentableNodes(Set<Class<? extends Tag
195194
}
196195
final int functionEndOffset = module.functionSourceCodeEndOffset(functionIndex);
197196
final DebugLineSection debugLineSection = debugFunction.lineMap().getLineIndexMap(functionStartOffset, functionEndOffset);
198-
final WasmInstrumentationSupportNode support = new WasmInstrumentationSupportNode(debugLineSection, source);
197+
final WasmInstrumentationSupportNode support = new WasmInstrumentationSupportNode(debugLineSection, sourceSection.getSource());
199198
final BinaryParser binaryParser = new BinaryParser(module, context, module.codeSection());
200199
final byte[] bytecode = binaryParser.createFunctionDebugBytecode(functionIndex, debugLineSection.offsetToLineIndexMap());
201200
final WasmFunctionNode functionNodeDuplicate = new WasmFunctionNode(functionNode, bytecode, support::notifyLine);
@@ -233,7 +232,7 @@ public final Object getScope(Frame frame, @SuppressWarnings("unused") boolean no
233232
} else {
234233
final WasmContext wasmContext = WasmContext.get(this);
235234
if (wasmContext != null) {
236-
sourceSection = debugFunction.computeSourceSection(wasmContext.debugSourceLoader(), wasmContext.environment());
235+
sourceSection = debugFunction.computeSourceSection(wasmContext.debugSourceLoader());
237236
}
238237
}
239238

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/nodes/WasmRootNode.java

+5
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,9 @@ public final String toString() {
142142
protected boolean isInstrumentable() {
143143
return false;
144144
}
145+
146+
@Override
147+
public boolean isInternal() {
148+
return true;
149+
}
145150
}

0 commit comments

Comments
 (0)