-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Provide GraalVM metadata and substitutions #1357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
e249c02
61c0127
f7ffe8a
db998ac
92ac5ae
7b10c60
18a1496
261841a
fe51f0e
7c8b08a
3929143
77cb614
a244a63
3bc66d2
be64442
faaba04
841f67b
c3ab8da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ | ||
{ | ||
"name":"org.bson.codecs.kotlin.DataClassCodecProvider" | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ | ||
{ | ||
"name":"org.bson.codecs.kotlinx.KotlinSerializerCodecProvider" | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ | ||
{ | ||
"name":"org.bson.codecs.record.RecordCodecProvider" | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,14 @@ | |
package com.mongodb; | ||
|
||
import com.mongodb.annotations.Immutable; | ||
import com.mongodb.internal.graalvm.substitution.SocketStreamFactorySubstitution; | ||
|
||
import static com.mongodb.assertions.Assertions.isTrueArgument; | ||
import static com.mongodb.assertions.Assertions.notNull; | ||
|
||
/** | ||
* Represents the location of a MongoD unix domain socket. | ||
* It is {@linkplain SocketStreamFactorySubstitution#create(ServerAddress) not supported in GraalVM native image}. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that because internal classes are excluded from our API docs, this |
||
* | ||
* <p>Requires the 'jnr.unixsocket' library.</p> | ||
* @since 3.7 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import com.mongodb.UnixServerAddress; | ||
import com.mongodb.connection.SocketSettings; | ||
import com.mongodb.connection.SslSettings; | ||
import com.mongodb.internal.graalvm.substitution.SocketStreamFactorySubstitution; | ||
import com.mongodb.spi.dns.InetAddressResolver; | ||
|
||
import javax.net.SocketFactory; | ||
|
@@ -53,8 +54,18 @@ public SocketStreamFactory(final InetAddressResolver inetAddressResolver, final | |
this.sslSettings = notNull("sslSettings", sslSettings); | ||
} | ||
|
||
/** | ||
* @see SocketStreamFactorySubstitution#create(ServerAddress) | ||
*/ | ||
@Override | ||
public Stream create(final ServerAddress serverAddress) { | ||
return createInternal(serverAddress); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no way to call the original implementation of a method that is being substituted. I had to introduce There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, something you really want this feature.... I follow the same pattern very (too) often. |
||
} | ||
|
||
/** | ||
* @see SocketStreamFactorySubstitution#create(ServerAddress) | ||
*/ | ||
private Stream createInternal(final ServerAddress serverAddress) { | ||
Stream stream; | ||
if (serverAddress instanceof UnixServerAddress) { | ||
if (sslSettings.isEnabled()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.mongodb.internal.graalvm.substitution; | ||
|
||
import com.mongodb.MongoCompressor; | ||
import com.oracle.svm.core.annotate.Substitute; | ||
import com.oracle.svm.core.annotate.TargetClass; | ||
|
||
@TargetClass(MongoCompressor.class) | ||
public final class MongoCompressorSubstitution { | ||
@Substitute | ||
public static MongoCompressor createSnappyCompressor() { | ||
throw new UnsupportedOperationException("Snappy compressor is not supported in GraalVM native image"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not for this PR, but I got Snappy working in native with some nasty work (for kafka and netty). You could reproduce the same kind of thing. See: |
||
} | ||
|
||
private MongoCompressorSubstitution() { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.mongodb.internal.graalvm.substitution; | ||
|
||
import com.mongodb.ServerAddress; | ||
import com.mongodb.UnixServerAddress; | ||
import com.mongodb.internal.connection.SocketStreamFactory; | ||
import com.mongodb.internal.connection.Stream; | ||
import com.oracle.svm.core.annotate.Alias; | ||
import com.oracle.svm.core.annotate.Substitute; | ||
import com.oracle.svm.core.annotate.TargetClass; | ||
|
||
import static com.mongodb.assertions.Assertions.fail; | ||
|
||
@TargetClass(SocketStreamFactory.class) | ||
public final class SocketStreamFactorySubstitution { | ||
@Substitute | ||
public Stream create(final ServerAddress serverAddress) { | ||
if (serverAddress instanceof UnixServerAddress) { | ||
throw new UnsupportedOperationException("UnixServerAddress is not supported in GraalVM native image"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, it might be possible to support it now. These substitutions are kind of old, like 4/5 years old and GraalVM evolved a lot in between. Note that the class will need to be marked as a runtime only class (cannot be initialized at build time) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Could you please help me understand why? I made the snappy compressor work without any tricks, just by collecting the reachability metadata with the tracing agent via the
P.S. Given that snappy compression works with GraalVM, I removed snappy-related substitutions. |
||
} | ||
return createInternal(serverAddress); | ||
} | ||
|
||
@Alias | ||
private Stream createInternal(final ServerAddress serverAddress) { | ||
throw fail(); | ||
} | ||
|
||
private SocketStreamFactorySubstitution() { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.mongodb.internal.graalvm.substitution; | ||
|
||
import org.graalvm.nativeimage.ImageInfo; | ||
|
||
import static com.mongodb.assertions.Assertions.fail; | ||
|
||
public final class Substitutions { | ||
/** | ||
* @throws AssertionError If called at native image run time, | ||
* unless the method body is substituted using the GraalVM native image technology. | ||
* If not called at native image run time, then does not throw. | ||
* @see SubstitutionsSubstitution#assertUsed() | ||
*/ | ||
public static void assertUsed() throws AssertionError { | ||
if (ImageInfo.inImageRuntimeCode()) { | ||
fail("The body of this method must be substituted when compiling using the GraalVM native image technology"); | ||
} | ||
} | ||
|
||
private Substitutions() { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2008-present MongoDB, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.mongodb.internal.graalvm.substitution; | ||
|
||
import com.oracle.svm.core.annotate.Substitute; | ||
import com.oracle.svm.core.annotate.TargetClass; | ||
|
||
@TargetClass(Substitutions.class) | ||
final class SubstitutionsSubstitution { | ||
@Substitute | ||
public static void assertUsed() { | ||
} | ||
|
||
private SubstitutionsSubstitution() { | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not have these in Quarkus. I need to try with that. It might fix the mongo crypt issues we have in native. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should all be removed now that they are in mongodb-crypt, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a ticket for that https://jira.mongodb.org/browse/JAVA-5408. But we can do it only when a new version of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leaving this unresolved since we agreed to keep this PR open until after mongodb-crypt release |
||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$mongocrypt_crypto_fn", | ||
"methods":[{"name":"crypt","parameterTypes":["com.sun.jna.Pointer","com.mongodb.crypt.capi.CAPI$mongocrypt_binary_t","com.mongodb.crypt.capi.CAPI$mongocrypt_binary_t","com.mongodb.crypt.capi.CAPI$mongocrypt_binary_t","com.mongodb.crypt.capi.CAPI$mongocrypt_binary_t","com.sun.jna.Pointer","com.mongodb.crypt.capi.CAPI$mongocrypt_status_t"] }] | ||
}, | ||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$mongocrypt_hash_fn", | ||
"methods":[{"name":"hash","parameterTypes":["com.sun.jna.Pointer","com.mongodb.crypt.capi.CAPI$mongocrypt_binary_t","com.mongodb.crypt.capi.CAPI$mongocrypt_binary_t","com.mongodb.crypt.capi.CAPI$mongocrypt_status_t"] }] | ||
}, | ||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$mongocrypt_hmac_fn", | ||
"methods":[{"name":"hmac","parameterTypes":["com.sun.jna.Pointer","com.mongodb.crypt.capi.CAPI$mongocrypt_binary_t","com.mongodb.crypt.capi.CAPI$mongocrypt_binary_t","com.mongodb.crypt.capi.CAPI$mongocrypt_binary_t","com.mongodb.crypt.capi.CAPI$mongocrypt_status_t"] }] | ||
}, | ||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$mongocrypt_log_fn_t", | ||
"methods":[{"name":"log","parameterTypes":["int","com.mongodb.crypt.capi.CAPI$cstring","int","com.sun.jna.Pointer"] }] | ||
}, | ||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$mongocrypt_random_fn", | ||
"methods":[{"name":"random","parameterTypes":["com.sun.jna.Pointer","com.mongodb.crypt.capi.CAPI$mongocrypt_binary_t","int","com.mongodb.crypt.capi.CAPI$mongocrypt_status_t"] }] | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
[ | ||
{ | ||
"name":"com.mongodb.BasicDBObject", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have a slightly different set of reflection registrations. But, I believe yours are more accurate.
jyemin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"methods":[{"name":"<init>","parameterTypes":[] }] | ||
}, | ||
{ | ||
"name":"com.mongodb.MongoNamespace", | ||
"allDeclaredFields":true, | ||
"queryAllDeclaredMethods":true, | ||
"queryAllDeclaredConstructors":true | ||
}, | ||
{ | ||
"name":"com.mongodb.WriteConcern", | ||
"allPublicFields":true | ||
}, | ||
{ | ||
"name":"com.mongodb.client.model.changestream.ChangeStreamDocument", | ||
"allDeclaredFields":true, | ||
"queryAllDeclaredMethods":true, | ||
"queryAllDeclaredConstructors":true, | ||
"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"] }] | ||
}, | ||
{ | ||
"name":"com.mongodb.client.model.changestream.SplitEvent", | ||
"allDeclaredFields":true, | ||
"queryAllDeclaredMethods":true, | ||
"queryAllDeclaredConstructors":true | ||
}, | ||
{ | ||
"name":"com.mongodb.client.model.changestream.TruncatedArray", | ||
"allDeclaredFields":true, | ||
"queryAllDeclaredMethods":true, | ||
"queryAllDeclaredConstructors":true | ||
}, | ||
{ | ||
"name":"com.mongodb.client.model.changestream.UpdateDescription", | ||
"allDeclaredFields":true, | ||
"queryAllDeclaredMethods":true, | ||
"queryAllDeclaredConstructors":true, | ||
"methods":[{"name":"<init>","parameterTypes":["java.util.List","org.bson.BsonDocument","java.util.List","org.bson.BsonDocument"] }] | ||
}, | ||
{ | ||
jyemin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"name":"com.mongodb.crypt.capi.CAPI", | ||
"allPublicFields":true, | ||
"queryAllDeclaredMethods":true | ||
}, | ||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$cstring", | ||
"methods":[{"name":"<init>","parameterTypes":[] }] | ||
}, | ||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$mongocrypt_binary_t", | ||
"methods":[{"name":"<init>","parameterTypes":[] }] | ||
}, | ||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$mongocrypt_crypto_fn", | ||
"queryAllDeclaredMethods":true, | ||
"queryAllPublicMethods":true | ||
}, | ||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$mongocrypt_ctx_t", | ||
"methods":[{"name":"<init>","parameterTypes":[] }] | ||
}, | ||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$mongocrypt_hash_fn", | ||
"queryAllDeclaredMethods":true, | ||
"queryAllPublicMethods":true | ||
}, | ||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$mongocrypt_hmac_fn", | ||
"queryAllDeclaredMethods":true, | ||
"queryAllPublicMethods":true | ||
}, | ||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$mongocrypt_kms_ctx_t", | ||
"methods":[{"name":"<init>","parameterTypes":[] }] | ||
}, | ||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$mongocrypt_log_fn_t", | ||
"queryAllDeclaredMethods":true, | ||
"queryAllPublicMethods":true | ||
}, | ||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$mongocrypt_random_fn", | ||
"queryAllDeclaredMethods":true, | ||
"queryAllPublicMethods":true | ||
}, | ||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$mongocrypt_status_t", | ||
"methods":[{"name":"<init>","parameterTypes":[] }] | ||
}, | ||
{ | ||
"name":"com.mongodb.crypt.capi.CAPI$mongocrypt_t", | ||
"methods":[{"name":"<init>","parameterTypes":[] }] | ||
} | ||
] |
Uh oh!
There was an error while loading. Please reload this page.