Skip to content

Commit

Permalink
Restructure binding packages and move common components to platform-s…
Browse files Browse the repository at this point in the history
…pecific BindingUtils classes.

Remove VH usages - replaced with jextract generated code modification.
  • Loading branch information
AlekseiEfimov committed Oct 31, 2024
1 parent d80a6de commit 842aef9
Show file tree
Hide file tree
Showing 32 changed files with 716 additions and 1,426 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package jdk.internal.ffi.generated;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.util.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;

@SuppressWarnings("restricted")
public final class BindingUtils {
private BindingUtils() {
}
public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN;
public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE;
public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT;
public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT;
public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG;
public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT;
public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE;
public static final AddressLayout C_POINTER = ValueLayout.ADDRESS
.withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE));
public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@

// Generated by jextract

package jdk.internal.bindings.net.socket.generated;
package jdk.internal.ffi.generated.socket;

import jdk.internal.ffi.generated.BindingUtils;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;

/**
Expand Down Expand Up @@ -83,9 +81,9 @@ public static class __in6_u {
}

private static final GroupLayout $LAYOUT = MemoryLayout.unionLayout(
MemoryLayout.sequenceLayout(16, socket_address_h.C_CHAR).withName("__u6_addr8"),
MemoryLayout.sequenceLayout(8, socket_address_h.C_SHORT).withName("__u6_addr16"),
MemoryLayout.sequenceLayout(4, socket_address_h.C_INT).withName("__u6_addr32")
MemoryLayout.sequenceLayout(16, BindingUtils.C_CHAR).withName("__u6_addr8"),
MemoryLayout.sequenceLayout(8, BindingUtils.C_SHORT).withName("__u6_addr16"),
MemoryLayout.sequenceLayout(4, BindingUtils.C_INT).withName("__u6_addr32")
).withName("$anon$221:5");

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@

// Generated by jextract

package jdk.internal.bindings.net.socket.generated;
package jdk.internal.ffi.generated.socket;

import jdk.internal.ffi.generated.BindingUtils;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;
Expand All @@ -52,7 +50,7 @@ public class in_addr {
}

private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
socket_address_h.C_INT.withName("s_addr")
BindingUtils.C_INT.withName("s_addr")
).withName("in_addr");

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* echo "#include <netinet/in.h>" > $HEADER_NAME
* echo "#include <sys/socket.h>" >> $HEADER_NAME
*
* jextract --target-package jdk.internal.bindings.net.socket.generated \
* jextract --target-package jdk.internal.ffi.generated.socket \
* --include-struct sockaddr \
* --include-constant AF_INET \
* --include-constant AF_INET6 \
Expand All @@ -43,6 +43,12 @@
* $HEADER_NAME
* }
*
* After generation of native bindings, the layouts for the C builtin layouts and other
* variables/methods not specific to a component area are moved to the {@code BindingUtils} class
* for future reusability.
* If the {@code BindingUtils} class already exists, any usage of the components mentioned above is
* replaced with matching replacement from the {@code BindingUtils} where possible.
*
*/

package jdk.internal.bindings.net.socket.generated;
package jdk.internal.ffi.generated.socket;
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@

// Generated by jextract

package jdk.internal.bindings.net.socket.generated;
package jdk.internal.ffi.generated.socket;

import jdk.internal.ffi.generated.BindingUtils;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;
Expand All @@ -53,8 +52,8 @@ public class sockaddr {
}

private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
socket_address_h.C_SHORT.withName("sa_family"),
MemoryLayout.sequenceLayout(14, socket_address_h.C_CHAR).withName("sa_data")
BindingUtils.C_SHORT.withName("sa_family"),
MemoryLayout.sequenceLayout(14, BindingUtils.C_CHAR).withName("sa_data")
).withName("sockaddr");

/**
Expand Down Expand Up @@ -104,8 +103,11 @@ public static short sa_family(MemorySegment struct) {
* sa_family_t sa_family
* }
*/
public static void sa_family(MemorySegment struct, short fieldValue) {
struct.set(sa_family$LAYOUT, sa_family$OFFSET, fieldValue);
public static void sa_family(MemorySegment struct, int fieldValue) {
// jextract generated code was modified to take family as int
// on all platforms, and added the cast to - short or byte,
// depending on a platform native structure.
struct.set(sa_family$LAYOUT, sa_family$OFFSET, (short) fieldValue);
}

private static final SequenceLayout sa_data$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("sa_data"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@

// Generated by jextract

package jdk.internal.bindings.net.socket.generated;
package jdk.internal.ffi.generated.socket;

import jdk.internal.ffi.generated.BindingUtils;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;
Expand All @@ -55,10 +54,10 @@ public class sockaddr_in {
}

private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
socket_address_h.C_SHORT.withName("sin_family"),
socket_address_h.C_SHORT.withName("sin_port"),
BindingUtils.C_SHORT.withName("sin_family"),
BindingUtils.C_SHORT.withName("sin_port"),
in_addr.layout().withName("sin_addr"),
MemoryLayout.sequenceLayout(8, socket_address_h.C_CHAR).withName("sin_zero")
MemoryLayout.sequenceLayout(8, BindingUtils.C_CHAR).withName("sin_zero")
).withName("sockaddr_in");

/**
Expand Down Expand Up @@ -108,8 +107,11 @@ public static short sin_family(MemorySegment struct) {
* sa_family_t sin_family
* }
*/
public static void sin_family(MemorySegment struct, short fieldValue) {
struct.set(sin_family$LAYOUT, sin_family$OFFSET, fieldValue);
public static void sin_family(MemorySegment struct, int fieldValue) {
// jextract generated code was modified to take family as int
// on all platforms, and added the cast to - short or byte,
// depending on a platform native structure.
struct.set(sin_family$LAYOUT, sin_family$OFFSET, (short) fieldValue);
}

private static final OfShort sin_port$LAYOUT = (OfShort)$LAYOUT.select(groupElement("sin_port"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@

// Generated by jextract

package jdk.internal.bindings.net.socket.generated;
package jdk.internal.ffi.generated.socket;

import jdk.internal.ffi.generated.BindingUtils;

import java.lang.invoke.*;
import java.lang.foreign.*;
import java.nio.ByteOrder;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;
Expand All @@ -56,11 +54,11 @@ public class sockaddr_in6 {
}

private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
socket_address_h.C_SHORT.withName("sin6_family"),
socket_address_h.C_SHORT.withName("sin6_port"),
socket_address_h.C_INT.withName("sin6_flowinfo"),
BindingUtils.C_SHORT.withName("sin6_family"),
BindingUtils.C_SHORT.withName("sin6_port"),
BindingUtils.C_INT.withName("sin6_flowinfo"),
in6_addr.layout().withName("sin6_addr"),
socket_address_h.C_INT.withName("sin6_scope_id")
BindingUtils.C_INT.withName("sin6_scope_id")
).withName("sockaddr_in6");

/**
Expand Down Expand Up @@ -110,8 +108,11 @@ public static short sin6_family(MemorySegment struct) {
* sa_family_t sin6_family
* }
*/
public static void sin6_family(MemorySegment struct, short fieldValue) {
struct.set(sin6_family$LAYOUT, sin6_family$OFFSET, fieldValue);
public static void sin6_family(MemorySegment struct, int fieldValue) {
// jextract generated code was modified to take family as int
// on all platforms, and added the cast to - short or byte,
// depending on a platform native structure.
struct.set(sin6_family$LAYOUT, sin6_family$OFFSET, (short) fieldValue);
}

private static final OfShort sin6_port$LAYOUT = (OfShort)$LAYOUT.select(groupElement("sin6_port"));
Expand Down
Loading

0 comments on commit 842aef9

Please sign in to comment.