From 98758e151b3257bf575066571ce16e362f58c636 Mon Sep 17 00:00:00 2001 From: Alexander Jordan Date: Tue, 4 May 2021 16:08:26 +0200 Subject: [PATCH] Try moving boundary away from adapter invocation There may be some optimization potential when frequent invocations of eg. `J$.iidToLocation` can be inlined. Should be tested/profiled. --- .../inf/nodeprof/jalangi/JalangiAdapter.java | 39 ++++++++++++++++--- .../usi/inf/nodeprof/utils/SourceMapping.java | 6 +-- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/ch.usi.inf.nodeprof/src/ch/usi/inf/nodeprof/jalangi/JalangiAdapter.java b/src/ch.usi.inf.nodeprof/src/ch/usi/inf/nodeprof/jalangi/JalangiAdapter.java index cc558501..2482b56c 100644 --- a/src/ch.usi.inf.nodeprof/src/ch/usi/inf/nodeprof/jalangi/JalangiAdapter.java +++ b/src/ch.usi.inf.nodeprof/src/ch/usi/inf/nodeprof/jalangi/JalangiAdapter.java @@ -122,8 +122,15 @@ private static int convertIID(Object argument) { return iid; } - @TruffleBoundary private static boolean checkArguments(int count, Object[] arguments, String funcName) throws ArityException { + if (arguments.length == count) { + return true; + } + return checkArgumentsSlow(count, arguments, funcName); + } + + @TruffleBoundary + private static boolean checkArgumentsSlow(int count, Object[] arguments, String funcName) throws ArityException { if (arguments.length < count) { Logger.error("call to " + funcName + " expects " + count + " argument(s)"); if (!GlobalConfiguration.IGNORE_JALANGI_EXCEPTION) { @@ -149,15 +156,35 @@ private Object getConfig() { return obj; } - @ExportMessage @TruffleBoundary - final Object invokeMember(String identifier, Object[] arguments) throws ArityException, UnsupportedTypeException { - ApiMember api; + ApiMember lookupApiMethod(String identifier) { try { - api = ApiMember.valueOf(identifier.toUpperCase()); + return ApiMember.valueOf(identifier.toUpperCase()); } catch (IllegalArgumentException e) { Logger.warning("Unsupported NodeProf-Jalangi operation " + identifier); - return 0; + } + return null; + } + + @ExportMessage + final Object invokeMember(String identifier, Object[] arguments) throws ArityException, UnsupportedTypeException { + ApiMember api; + switch (identifier) { + case "iidToLocation": + api = ApiMember.IIDTOLOCATION; + break; + case "iidToCode": + api = ApiMember.IIDTOCODE; + break; + case "nativeLog": + api = ApiMember.NATIVELOG; + break; + default: + api = lookupApiMethod(identifier); + if (api == null) { + return null; + } + break; } switch (api) { case IIDTOLOCATION: { diff --git a/src/ch.usi.inf.nodeprof/src/ch/usi/inf/nodeprof/utils/SourceMapping.java b/src/ch.usi.inf.nodeprof/src/ch/usi/inf/nodeprof/utils/SourceMapping.java index 9148825b..1959bfc8 100644 --- a/src/ch.usi.inf.nodeprof/src/ch/usi/inf/nodeprof/utils/SourceMapping.java +++ b/src/ch.usi.inf.nodeprof/src/ch/usi/inf/nodeprof/utils/SourceMapping.java @@ -1,6 +1,6 @@ /******************************************************************************* * Copyright 2018 Dynamic Analysis Group, Università della Svizzera Italiana (USI) - * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -66,7 +66,7 @@ public static int getIIDForSourceSection(SourceSection sourceSection) { return newIId; } - @TruffleBoundary + @TruffleBoundary(allowInlining = true) public static String getLocationForIID(int iid) { if (iidToLocationCache.containsKey(iid)) { return iidToLocationCache.get(iid); @@ -79,7 +79,7 @@ public static String getLocationForIID(int iid) { } } - @TruffleBoundary + @TruffleBoundary(allowInlining = true) public static String getCodeForIID(int iid) { if (idToSource.containsKey(iid)) { return idToSource.get(iid).getCharacters().toString();