Trying to use native-image with a small test program that creates a Postgres JDBC Connection.
I'm using:
$ java -version
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-12)
GraalVM 1.0.0-rc1 (build 25.71-b01-internal-jvmci-0.42, mixed mode)
Getting the exception below.
[main] INFO org.avaje.datasource.pool.ConnectionPool - DataSourcePool [db] autoCommit[false] transIsolation[READ_COMMITTED] min[2] max[200]
May 31, 2018 10:07:05 PM org.postgresql.Driver
WARNING: Can't find a classloader for the Driver; not loading driver configuration
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.lang.Throwable.<init>(Throwable.java:310)
at java.lang.Exception.<init>(Exception.java:102)
at java.lang.ReflectiveOperationException.<init>(ReflectiveOperationException.java:89)
at java.lang.reflect.InvocationTargetException.<init>(InvocationTargetException.java:72)
at com.oracle.svm.reflect.proxies.Proxy_1_InsertMain_main.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:199)
at Lcom/oracle/svm/core/code/CEntryPointCallStubs;.com_002eoracle_002esvm_002ecore_002eJavaMainWrapper_002erun_0028int_002corg_002egraalvm_002enativeimage_002ec_002etype_002eCCharPointerPointer_0029(generated:0)
Caused by: com.oracle.svm.core.jdk.UnsupportedFeatureError: unimplemented
at java.lang.Throwable.<init>(Throwable.java:265)
at java.lang.Error.<init>(Error.java:70)
at com.oracle.svm.core.jdk.UnsupportedFeatureError.<init>(UnsupportedFeatureError.java:29)
at com.oracle.svm.core.jdk.Target_com_oracle_svm_core_util_VMError.unsupportedFeature(VMErrorSubstitutions.java:103)
at com.oracle.svm.core.jdk.Target_com_oracle_svm_core_util_VMError.unimplemented(VMErrorSubstitutions.java:97)
at com.oracle.svm.core.posix.Target_java_net_PlainSocketImpl.socketGetOption(PosixJavaNetSubstitutions.java:2958)
at java.net.AbstractPlainSocketImpl.getOption(AbstractPlainSocketImpl.java:312)
at java.net.Socket.getReceiveBufferSize(Socket.java:1291)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:198)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
at org.postgresql.Driver.makeConnection(Driver.java:452)
at org.postgresql.Driver.connect(Driver.java:254)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at org.avaje.datasource.pool.ConnectionPool.createUnpooledConnection(ConnectionPool.java:432)
at org.avaje.datasource.pool.ConnectionPool.createConnectionForQueue(ConnectionPool.java:668)
at org.avaje.datasource.pool.PooledConnectionQueue.ensureMinimumConnections(PooledConnectionQueue.java:228)
at org.avaje.datasource.pool.ConnectionPool.initialise(ConnectionPool.java:275)
at org.avaje.datasource.pool.ConnectionPool.<init>(ConnectionPool.java:225)
at org.avaje.datasource.core.Factory.createPool(Factory.java:15)
at org.example.InsertMain.main(InsertMain.java:23)
... 4 more
I did build the image with native-image -H:+ReportUnsupportedElementsAtRuntime -H:ReflectionConfigurationFiles=../reflectconfig.json -jar app.jar
reflectconfig.json is:
[
{
"name" : "org.postgresql.Driver",
"allDeclaredMethods" : true,
"allPublicMethods" : true
}
]
It just looks like PlainSocketImpl.socketGetOption(PosixJavaNetSubstitutions.java:2958) is not implemented yet.
Building without -H:+ReportUnsupportedElementsAtRuntime produces:
$ native-image -H:ReflectionConfigurationFiles=../reflectconfig.json -jar app.jarWarning: Native image server limit exceeded. Use options --server{-list,-shutdown[-all]} to fix the problem.
classlist: 749.02 ms
(cap): 1,116.34 ms
setup: 2,064.07 ms
analysis: 8,655.94 ms
error: unsupported features in 3 methods
Detailed message:
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Unsupported method java.lang.ref.Reference.enqueue() is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class
To diagnose the issue, you can add the option -H:+ReportUnsupportedElementsAtRuntime. The unsupported element is then reported at run time when it is accessed the first time.
Trace:
at parsing org.postgresql.core.v3.Portal.close(Portal.java:30)
Call path from entry point to org.postgresql.core.v3.Portal.close():
at org.postgresql.core.v3.Portal.close(Portal.java:28)
at org.postgresql.jdbc.PgResultSet.close(PgResultSet.java:1879)
at org.postgresql.jdbc.TypeInfoCache.getArrayDelimiter(TypeInfoCache.java:497)
at org.postgresql.jdbc.PgArray.toString(PgArray.java:912)
at java.lang.String.valueOf(String.java:2994)
at java.lang.StringBuilder.append(StringBuilder.java:131)
at com.oracle.svm.core.amd64.AMD64CPUFeatureAccess.verifyHostSupportsArchitecture(AMD64CPUFeatureAccess.java:163)
at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:180)
at Lcom/oracle/svm/core/code/CEntryPointCallStubs;.com_002eoracle_002esvm_002ecore_002eJavaMainWrapper_002erun_0028int_002corg_002egraalvm_002enativeimage_002ec_002etype_002eCCharPointerPointer_0029(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Unsupported method java.lang.ref.Reference.enqueue() is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class
To diagnose the issue, you can add the option -H:+ReportUnsupportedElementsAtRuntime. The unsupported element is then reported at run time when it is accessed the first time.
Trace:
at parsing org.postgresql.core.v3.SimpleQuery.setCleanupRef(SimpleQuery.java:290)
Call path from entry point to org.postgresql.core.v3.SimpleQuery.setCleanupRef(PhantomReference):
at org.postgresql.core.v3.SimpleQuery.setCleanupRef(SimpleQuery.java:288)
at org.postgresql.core.v3.QueryExecutorImpl.registerParsedQuery(QueryExecutorImpl.java:1882)
at org.postgresql.core.v3.QueryExecutorImpl.sendParse(QueryExecutorImpl.java:1397)
at org.postgresql.core.v3.QueryExecutorImpl.sendOneQuery(QueryExecutorImpl.java:1762)
at org.postgresql.core.v3.QueryExecutorImpl.sendAutomaticSavepoint(QueryExecutorImpl.java:355)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)
at org.postgresql.jdbc.PgConnection.executeTransactionCommand(PgConnection.java:740)
at org.postgresql.jdbc.PgConnection.commit(PgConnection.java:761)
at org.postgresql.jdbc.PgConnection.setAutoCommit(PgConnection.java:720)
at org.avaje.datasource.pool.PooledConnection.close(PooledConnection.java:490)
at org.example.InsertMain.main(InsertMain.java:31)
at com.oracle.svm.reflect.proxies.Proxy_1_InsertMain_main.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:199)
at Lcom/oracle/svm/core/code/CEntryPointCallStubs;.com_002eoracle_002esvm_002ecore_002eJavaMainWrapper_002erun_0028int_002corg_002egraalvm_002enativeimage_002ec_002etype_002eCCharPointerPointer_0029(generated:0)
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Unsupported method java.lang.ref.Reference.enqueue() is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class
To diagnose the issue, you can add the option -H:+ReportUnsupportedElementsAtRuntime. The unsupported element is then reported at run time when it is accessed the first time.
Trace:
at parsing org.postgresql.core.v3.SimpleQuery.unprepare(SimpleQuery.java:298)
Call path from entry point to org.postgresql.core.v3.SimpleQuery.unprepare():
at org.postgresql.core.v3.SimpleQuery.unprepare(SimpleQuery.java:296)
at org.postgresql.core.v3.SimpleQuery.close(SimpleQuery.java:62)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:372)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:155)
at org.postgresql.jdbc.TypeInfoCache.getArrayDelimiter(TypeInfoCache.java:483)
at org.postgresql.jdbc.PgArray.toString(PgArray.java:912)
at java.lang.String.valueOf(String.java:2994)
at java.lang.StringBuilder.append(StringBuilder.java:131)
at com.oracle.svm.core.amd64.AMD64CPUFeatureAccess.verifyHostSupportsArchitecture(AMD64CPUFeatureAccess.java:163)
at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:180)
at Lcom/oracle/svm/core/code/CEntryPointCallStubs;.com_002eoracle_002esvm_002ecore_002eJavaMainWrapper_002erun_0028int_002corg_002egraalvm_002enativeimage_002ec_002etype_002eCCharPointerPointer_0029(generated:0)
Error: Image building with exit status 1
@rbygrave thank you for your report. You are right, PlainSocketImpl.socketGetOption(PosixJavaNetSubstitutions.java:2958) is not currently implemented.
are there any workarounds or do we simply need to wait for the implementation?
Somehow the request for an implementation of Target_java_net_PlainSocketImpl.socketGetOption never made it into an internal issue. I have now filed one.
You can either wait for us to implement it, or (unlikely) implement it yourself.
These issues are not public right?
Fixed in https://github.com/oracle/graal/commit/8aea51dd9122b3651eef2529b3edc70b21824cbd, which should be in our August release.
Most helpful comment
Somehow the request for an implementation of
Target_java_net_PlainSocketImpl.socketGetOptionnever made it into an internal issue. I have now filed one.You can either wait for us to implement it, or (unlikely) implement it yourself.