How do I resoove this Mac GraalVM Error When Running JavaScript Example - graalvm

After installing the latest GraalVM on the Mac (GraalVM CE 20.1.0), and running this code segment:
public static void main(String[] args)
{
// Context context = Context.create();
Context context = Context.newBuilder().allowAllAccess(true).build();
String strToEval = "print(eval('1+3'))";`
context.eval("js", "print(eval('1+3'));");
context.eval("js", "print(eval('Math.PI/2'));");
}
I get this error:
java: java.lang.IllegalAccessError: class com.oracle.truffle.dsl.processor.TruffleProcessor (in unnamed module #0xd2331f5) cannot access class com.oracle.truffle.api.dsl.Fallback (in module org.graalvm.truffle) because module org.graalvm.truffle does not export com.oracle.truffle.api.dsl to unnamed module #0xd2331f5
How to fix this?
Thanks,

Related

Fatal error with JNA structure

I have a problem with a very simple example in jna. I would like to read and write in a structure in C with java. I compiled a very simple example in c:
typedef struct {
int x;
} MyStruct;
I created the corresponding class in java with JNA:
import java.util.List;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
public class MyStruct extends Structure {
public int x;
public MyStruct(Pointer p) {
super(p);
}
#Override
protected List<String> getFieldOrder() {
return List.of("x");
}
}
And I created a program to test the structure:
public class JnaJava {
public static void main(String[] args) {
NativeLibrary lib = NativeLibrary.getInstance(new File("libJnaC.so").getAbsolutePath());
MyStruct struct = new MyStruct(lib.getGlobalVariableAddress("myStruct"));
for (int i = 0; i < 2000000000; i++) {
struct.writeField("x", i);
System.out.println("val: " + struct.readField("x") + " it: " + i);
}
}
}
But I have an error around the 400.000 iterations:
...
val: 448536 it: 448536
# A fatal error has been detected by the Java Runtime Environment:
# SIGSEGV (0xb) at pc=0x00007fb3d89e537b, pid=14464, tid=14466
# JRE version: Java(TM) SE Runtime Environment (10.0+46) (build 10+46)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (10+46, mixed mode, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# C [jna8855397332554224295.tmp+0x837b] Java_com_sun_jna_Native_setInt+0xab
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
# An error report file with more information is saved as:
# /home/X/workspace/JnaJava/hs_err_pid14464.log
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
Can someone tell me where is my mistake? It sounds like a strange memory bug but I don't know why?
Thanks in advance
Marc
It was just a stupid GC problem. Put the variable in in a strong reference solved the problem.
https://groups.google.com/forum/#!topic/jna-users/4g3fLVi8Gxw

Using java class in Xamarin

I have a Xamarin.Android project. How can I use java class declared in java file from C# code? How can I reference to it?
That is what I did:
1) I've added java file to project,
2) set up build action to AndroidJavaSource
3) Compiled (and seen Foo.class in obj folder)
Foo.java
package x.y.z;
public class Foo{
}
How can I reference to Foo from C#?
var f = new Foo();
f.someFunction();
I've solved it!
Instance is created by
Java.Lang.Object obj = Java.Lang.Class.ForName("x.y.z.Foo").NewInstance();
You can cast Java.Lang.Object to a known ancestor if necessary.

Trying to trigger JMX Mbean functions from command line

My application is running on Wildfly-8.0.1. Currently, I am able to trigger MBean methods through JConsole using service:jmx:http-remoting-jmx://localhost:9990.
I want to write some script to trigger those commands but I didn't find a supporting tool to accomplish that.
I tried below tools, but it seems like they are not supporting http-remoting-jmx protocol or may be I am not using in right way
1. JMXTerm
2. Cmdline_JMXClient
3. JManage
4. CJMX
Here is the error from JMXTerm
$>open service:jmx:http-remoting-jmx://localhost:9990
RuntimeIOException: Runtime IO exception: Unsupported protocol: http-remoting-j
mx
any help would greatly be appreciated.
Create custom jar file using below class.
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
public class JMXCli {
//private static List<String> operations;
private static final String SERVICE_URL = "service:jmx:http-remoting-jmx://";
public static void main(String[] args) throws Exception {
JMXServiceURL url = new JMXServiceURL(SERVICE_URL + args[0]);
JMXConnector connector = JMXConnectorFactory.connect(url);
MBeanServerConnection connection = connector.getMBeanServerConnection();
ObjectName objectName = new ObjectName("com.xyz.com:name=<<Your MBean class name>>");
System.out.println(connection.invoke(objectName, args[1], null, null));
}
}

Driver null while opening session in Neo4j OGM Java driver v2

I put ogm.properties file in the same folder as class Neo4jSessionFactory. When I run my project I get information that driver is "null". What is the problem? I use Neo4j OGM driver for Java in version 2.
My session factory class:
public class Neo4jSessionFactory {
private final static SessionFactory sessionFactory =
new SessionFactory("school.domain");
private static final Neo4jSessionFactory factory = new Neo4jSessionFactory();
public static Neo4jSessionFactory getInstance() {
return factory;
}
public Session getNeo4jSession() {
return sessionFactory.openSession();
}
}
Stack trace:
Exception in thread "main" org.neo4j.ogm.exception.ServiceNotFoundException: Driver: null
at org.neo4j.ogm.service.DriverService.load(DriverService.java:51)
at org.neo4j.ogm.service.DriverService.load(DriverService.java:63)
at org.neo4j.ogm.service.Components.loadDriver(Components.java:126)
at org.neo4j.ogm.service.Components.driver(Components.java:84)
at org.neo4j.ogm.session.SessionFactory.openSession(SessionFactory.java:80)
at neo4jCMS.Neo4jSessionFactory.getNeo4jSession(Neo4jSessionFactory.java:27)
at neo4jCMS.Application.main(Application.java:20)
My ogm.properties file:
driver=org.neo4j.ogm.drivers.http.driver.HttpDriver
URI=http://login:password#localhost:7474
I put ogm.properties file in the same folder as class Neo4jSessionFactory.
The easiest way to use the ogm.properties is to put them at the root of the classpath. You don't need to put it in the same folder as the Neo4jSessionFactory or where you instantiate the factory in your app.

Vala: number of cpus

I am trying to get my machine's number of cpus in vala.
According to http://valadoc.org/#!wiki=glib-2.0/index
public uint get_num_processors ()
should return this to me.
But when I try to compile the following code:
public class Main {
static int main(string[] args) {
uint num_cpus = GLib.get_num_processors();
return 0;
}
}
with:
valac --target-glib 2.38 --pkg gtk+-3.0 --pkg gee-1.0 $(SRC)
I see the following error:
Application.vala:28.4-28.26: error: The name 'get_num_processors' does
not exist in the context of 'GLib'
I've tested some other methods from GLib. They all work flawless except this one.
Has anyone an idea what I'm doing wrong?
The function was only added to the VAPI recently, I believe you'll need version 0.22.0 of Vala (or one of the unstable 0.21.x releases).
To get around this you can create a local binding in your code:
[CCode (cname = "g_get_num_processors")]
private extern static uint get_num_processors ();
This was introduced in GLib 2.36 (see GLib Threads). Do you have that version installed?

Resources