Skip to content

Commit eea937c

Browse files
authored
Provide GraalVM metadata and substitutions (#1357)
JAVA-5219 JAVA-5408
1 parent 7e3108b commit eea937c

File tree

20 files changed

+357
-529
lines changed

20 files changed

+357
-529
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"name":"java.lang.Object",
4+
"queryAllDeclaredMethods":true
5+
},
6+
{
7+
"name":"sun.security.provider.NativePRNG",
8+
"methods":[{"name":"<init>","parameterTypes":[] }, {"name":"<init>","parameterTypes":["java.security.SecureRandomParameters"] }]
9+
},
10+
{
11+
"name":"sun.security.provider.SHA",
12+
"methods":[{"name":"<init>","parameterTypes":[] }]
13+
},
14+
{
15+
"name":"org.slf4j.Logger"
16+
}
17+
]

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ ext {
5858
projectReactorVersion = '2022.0.0'
5959
junitBomVersion = '5.10.2'
6060
logbackVersion = '1.3.14'
61+
graalSdkVersion = '24.0.0'
6162
gitVersion = getGitVersion()
6263
}
6364

driver-core/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ dependencies {
4646
api "io.netty:netty-buffer", optional
4747
api "io.netty:netty-transport", optional
4848
api "io.netty:netty-handler", optional
49+
compileOnly "org.graalvm.sdk:graal-sdk:$graalSdkVersion"
4950

5051
// Optionally depend on both AWS SDK v2 and v1. The driver will use v2 is present, v1 if present, or built-in functionality if
5152
// neither are present

driver-core/src/main/com/mongodb/UnixServerAddress.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
package com.mongodb;
1818

1919
import com.mongodb.annotations.Immutable;
20+
import com.mongodb.internal.graalvm.substitution.UnixServerAddressSubstitution;
2021

2122
import static com.mongodb.assertions.Assertions.isTrueArgument;
2223
import static com.mongodb.assertions.Assertions.notNull;
2324

2425
/**
2526
* Represents the location of a MongoD unix domain socket.
27+
* It is {@linkplain UnixServerAddressSubstitution not supported in GraalVM native image}.
2628
*
2729
* <p>Requires the 'jnr.unixsocket' library.</p>
2830
* @since 3.7
@@ -34,10 +36,18 @@ public final class UnixServerAddress extends ServerAddress {
3436
/**
3537
* Creates a new instance
3638
* @param path the path of the MongoD unix domain socket.
39+
* @throws UnsupportedOperationException If {@linkplain UnixServerAddressSubstitution called in a GraalVM native image}.
3740
*/
3841
public UnixServerAddress(final String path) {
3942
super(notNull("The path cannot be null", path));
4043
isTrueArgument("The path must end in .sock", path.endsWith(".sock"));
44+
checkNotInGraalVmNativeImage();
45+
}
46+
47+
/**
48+
* @throws UnsupportedOperationException If {@linkplain UnixServerAddressSubstitution called in a GraalVM native image}.
49+
*/
50+
private static void checkNotInGraalVmNativeImage() {
4151
}
4252

4353
@Override

driver-core/src/main/com/mongodb/internal/dns/JndiDnsClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
import java.util.Hashtable;
3333
import java.util.List;
3434

35-
final class JndiDnsClient implements DnsClient {
35+
/**
36+
* <p>This class is not part of the public API and may be removed or changed at any time</p>
37+
*/
38+
public final class JndiDnsClient implements DnsClient {
3639

3740
@Override
3841
public List<String> getResourceRecordData(final String name, final String type) throws DnsException {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2008-present MongoDB, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.mongodb.internal.graalvm.substitution;
17+
18+
import com.mongodb.UnixServerAddress;
19+
import com.oracle.svm.core.annotate.Substitute;
20+
import com.oracle.svm.core.annotate.TargetClass;
21+
22+
@TargetClass(UnixServerAddress.class)
23+
public final class UnixServerAddressSubstitution {
24+
@Substitute
25+
private static void checkNotInGraalVmNativeImage() {
26+
throw new UnsupportedOperationException("UnixServerAddress is not supported in GraalVM native image");
27+
}
28+
29+
private UnixServerAddressSubstitution() {
30+
}
31+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ Args =\
1818
com.mongodb.UnixServerAddress,\
1919
com.mongodb.internal.connection.SnappyCompressor,\
2020
com.mongodb.internal.connection.ClientMetadataHelper,\
21-
com.mongodb.internal.connection.ServerAddressHelper
21+
com.mongodb.internal.connection.ServerAddressHelper,\
22+
com.mongodb.internal.dns.DefaultDnsResolver
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
[
2+
{
3+
"name":"com.mongodb.BasicDBObject",
4+
"methods":[{"name":"<init>","parameterTypes":[] }]
5+
},
6+
{
7+
"name":"com.mongodb.MongoNamespace",
8+
"allDeclaredFields":true,
9+
"queryAllDeclaredMethods":true,
10+
"queryAllDeclaredConstructors":true
11+
},
12+
{
13+
"name":"com.mongodb.WriteConcern",
14+
"allPublicFields":true
15+
},
16+
{
17+
"name":"com.mongodb.client.model.changestream.ChangeStreamDocument",
18+
"allDeclaredFields":true,
19+
"queryAllDeclaredMethods":true,
20+
"queryAllDeclaredConstructors":true,
21+
"methods":[{"name":"<init>","parameterTypes":["java.lang.String","org.bson.BsonDocument","org.bson.BsonDocument","org.bson.BsonDocument","java.lang.Object","java.lang.Object","org.bson.BsonDocument","org.bson.BsonTimestamp","com.mongodb.client.model.changestream.UpdateDescription","org.bson.BsonInt64","org.bson.BsonDocument","org.bson.BsonDateTime","com.mongodb.client.model.changestream.SplitEvent","org.bson.BsonDocument"] }]
22+
},
23+
{
24+
"name":"com.mongodb.client.model.changestream.SplitEvent",
25+
"allDeclaredFields":true,
26+
"queryAllDeclaredMethods":true,
27+
"queryAllDeclaredConstructors":true
28+
},
29+
{
30+
"name":"com.mongodb.client.model.changestream.TruncatedArray",
31+
"allDeclaredFields":true,
32+
"queryAllDeclaredMethods":true,
33+
"queryAllDeclaredConstructors":true
34+
},
35+
{
36+
"name":"com.mongodb.client.model.changestream.UpdateDescription",
37+
"allDeclaredFields":true,
38+
"queryAllDeclaredMethods":true,
39+
"queryAllDeclaredConstructors":true,
40+
"methods":[{"name":"<init>","parameterTypes":["java.util.List","org.bson.BsonDocument","java.util.List","org.bson.BsonDocument"] }]
41+
},
42+
{
43+
"name":"java.lang.Record"
44+
},
45+
{
46+
"name":"java.lang.Thread",
47+
"fields":[{"name":"threadLocalRandomProbe"}]
48+
},
49+
{
50+
"name":"java.net.Socket",
51+
"methods":[{"name":"setOption","parameterTypes":["java.net.SocketOption","java.lang.Object"] }]
52+
},
53+
{
54+
"name":"java.security.SecureRandomParameters"
55+
},
56+
{
57+
"name":"java.util.concurrent.ForkJoinTask",
58+
"fields":[{"name":"aux"}, {"name":"status"}]
59+
},
60+
{
61+
"name":"java.util.concurrent.atomic.Striped64",
62+
"fields":[{"name":"base"}, {"name":"cellsBusy"}]
63+
},
64+
{
65+
"name":"jdk.internal.misc.Unsafe"
66+
},
67+
{
68+
"name":"jdk.net.ExtendedSocketOptions",
69+
"fields":[{"name":"TCP_KEEPCOUNT"}, {"name":"TCP_KEEPIDLE"}, {"name":"TCP_KEEPINTERVAL"}]
70+
},
71+
{
72+
"name":"org.bson.codecs.kotlin.DataClassCodecProvider"
73+
},
74+
{
75+
"name":"org.bson.codecs.kotlinx.KotlinSerializerCodecProvider"
76+
},
77+
{
78+
"name":"org.bson.codecs.record.RecordCodecProvider"
79+
},
80+
{
81+
"name":"org.slf4j.Logger"
82+
}
83+
]

driver-core/src/main/resources/META-INF/native-image/resource-config.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"resources":{
33
"includes":[{
4+
"pattern":"\\QMETA-INF/services/com.mongodb.spi.dns.DnsClientProvider\\E"
5+
}, {
46
"pattern":"\\QMETA-INF/services/com.mongodb.spi.dns.InetAddressResolverProvider\\E"
57
}]},
68
"bundles":[]

0 commit comments

Comments
 (0)