Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from keithc-ca/jep424
Browse files Browse the repository at this point in the history
Several JEP424 fixes
  • Loading branch information
tajila authored Jul 28, 2022
2 parents f049f41 + 849bb44 commit 4e70209
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2022, 2022 All Rights Reserved
* ===========================================================================
*/

package java.lang.invoke;

import jdk.internal.foreign.AbstractMemorySegmentImpl;
Expand All @@ -42,8 +35,6 @@ import java.util.Objects;

import static java.lang.invoke.MethodHandleStatics.UNSAFE;

import sun.security.action.GetPropertyAction;

#warn

final class VarHandleSegmentAs$Type$s extends VarHandleSegmentViewBase {
Expand All @@ -56,8 +47,6 @@ final class VarHandleSegmentAs$Type$s extends VarHandleSegmentViewBase {

static final VarForm FORM = new VarForm(VarHandleSegmentAs$Type$s.class, MemorySegment.class, $type$.class, long.class);

static final boolean isAixOS = GetPropertyAction.privilegedGetProperty("os.name").startsWith("AIX") ? true : false;

VarHandleSegmentAs$Type$s(boolean be, long length, long alignmentMask, boolean exact) {
super(FORM, be, length, alignmentMask, exact);
}
Expand Down Expand Up @@ -117,36 +106,20 @@ final class VarHandleSegmentAs$Type$s extends VarHandleSegmentViewBase {
@ForceInline
static long offset(AbstractMemorySegmentImpl bb, long offset, long alignmentMask) {
long address = offsetNoVMAlignCheck(bb, offset, alignmentMask);
#if[floatingPoint]
/* Ignore the alignement check for float/double on AIX/PPC to handle the case of [float/int, double]
* given the size of [float/int, double] on AIX/PPC 64-bit is 12 bytes without padding while the
* same struct is 16 bytes with padding on other platforms
*/
if (!isAixOS) {
if ((address & VM_ALIGN) != 0) {
throw VarHandleSegmentViewBase.newIllegalArgumentExceptionForMisalignedAccess(address);
}
if ((address & VM_ALIGN) != 0) {
throw VarHandleSegmentViewBase.newIllegalArgumentExceptionForMisalignedAccess(address);
}
#end[floatingPoint]
return address;
}

@ForceInline
static long offsetNoVMAlignCheck(AbstractMemorySegmentImpl bb, long offset, long alignmentMask) {
long base = bb.unsafeGetOffset();
long address = base + offset;
#if[floatingPoint]
/* Ignore the alignement check for float/double on AIX/PPC to handle the case of [float/int, double]
* given the size of [float/int, double] on AIX/PPC 64-bit is 12 bytes without padding while the
* same struct is 16 bytes with padding on other platforms
*/
if (!isAixOS) {
long maxAlignMask = bb.maxAlignMask();
if (((address | maxAlignMask) & alignmentMask) != 0) {
throw VarHandleSegmentViewBase.newIllegalArgumentExceptionForMisalignedAccess(address);
}
long maxAlignMask = bb.maxAlignMask();
if (((address | maxAlignMask) & alignmentMask) != 0) {
throw VarHandleSegmentViewBase.newIllegalArgumentExceptionForMisalignedAccess(address);
}
#end[floatingPoint]
return address;
}

Expand Down
6 changes: 3 additions & 3 deletions src/java.base/share/classes/jdk/internal/foreign/CABI.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public enum CABI {
} else {
current = AIX;
}
} else if (arch.equals("s390x") && os.startsWith("Linux")) {
current = SysVS390x;
} else {
} else if (arch.equals("s390x") && os.startsWith("Linux")) {
current = SysVS390x;
} else {
throw new UnsupportedOperationException(
"Unsupported os, arch, or address size: " + os + ", " + arch + ", " + addressSize);
}
Expand Down
20 changes: 1 addition & 19 deletions src/java.base/share/classes/jdk/internal/foreign/LayoutPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
* questions.
*
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2022, 2022 All Rights Reserved
* ===========================================================================
*/

package jdk.internal.foreign;

import jdk.internal.vm.annotation.ForceInline;
Expand All @@ -47,8 +40,6 @@
import java.util.Objects;
import java.util.function.UnaryOperator;

import sun.security.action.GetPropertyAction;

/**
* This class provide support for constructing layout paths; that is, starting from a root path (see {@link #rootPath(MemoryLayout)},
* a path can be constructed by selecting layout elements using the selector methods provided by this class
Expand All @@ -61,7 +52,6 @@ public class LayoutPath {

private static final MethodHandle MH_ADD_SCALED_OFFSET;
private static final MethodHandle MH_SLICE;
private static final boolean isAixOS = GetPropertyAction.privilegedGetProperty("os.name").startsWith("AIX") ? true : false;

static {
try {
Expand Down Expand Up @@ -153,15 +143,7 @@ public VarHandle dereferenceHandle() {
if (!(layout instanceof ValueLayout valueLayout)) {
throw new IllegalArgumentException("Path does not select a value layout");
}

/* Ignore the alignement check for float/double on AIX/PPC to handle the case of [float/int, double]
* given the size of [float/int, double] on AIX/PPC 64-bit is 12 bytes without padding while the
* same struct is 16 bytes with padding on other platforms
*/
Class<?> javaType = valueLayout.carrier();
if (!isAixOS || ((javaType != float.class) && (javaType != double.class))) {
checkAlignment(this);
}
checkAlignment(this);

VarHandle handle = Utils.makeSegmentViewVarHandle(valueLayout);
for (int i = strides.length - 1; i >= 0; i--) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private AIX() {
/**
* The {@code long long} native type.
*/
public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG.withBitAlignment(64);
public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG.withBitAlignment(32);

/**
* The {@code float} native type.
Expand All @@ -389,12 +389,12 @@ private AIX() {
/**
* The {@code double} native type.
*/
public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE.withBitAlignment(64);
public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE.withBitAlignment(32);

/**
* The {@code T*} native type.
*/
public static final ValueLayout.OfAddress C_POINTER = ValueLayout.ADDRESS.withBitAlignment(64);
public static final ValueLayout.OfAddress C_POINTER = ValueLayout.ADDRESS.withBitAlignment(32);

/**
* The {@code va_list} native type, as it is passed to a function.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import jdk.internal.loader.NativeLibrary;
import jdk.internal.loader.NativeLibraries;
import jdk.internal.loader.NativeLibrary;
import jdk.internal.loader.RawNativeLibraries;
import sun.security.action.GetPropertyAction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* ===========================================================================
*/


package jdk.internal.foreign.abi.x64.windows;

import jdk.internal.foreign.Utils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
* questions.
*/


/*
* ===========================================================================
* (c) Copyright IBM Corp. 2022, 2022 All Rights Reserved
Expand Down
10 changes: 5 additions & 5 deletions src/java.base/share/native/libjava/NativeLibraries.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ Java_jdk_internal_loader_NativeLibraries_findBuiltinLib
return NULL;
}

#ifdef _AIX
#if defined(_AIX)
/*
* Class: jdk_internal_loader_NativeLibraries
* Method: findEntryInProcess
Expand All @@ -318,20 +318,20 @@ JNIEXPORT jlong JNICALL
Java_jdk_internal_loader_NativeLibraries_findEntryInProcess
(JNIEnv *env, jclass cls, jstring name)
{
const char *cname;
jlong res;
const char *cname = NULL;
jlong res = 0;

if (!initIDs(env)) {
return jlong_zero;
}

cname = (*env)->GetStringUTFChars(env, name, 0);
if (0 == cname) {
if (NULL == cname) {
return jlong_zero;
}

res = ptr_to_jlong(findEntryInProcess(cname));
(*env)->ReleaseStringUTFChars(env, name, cname);
return res;
}
#endif /* _AIX */
#endif /* defined(_AIX) */
6 changes: 3 additions & 3 deletions src/java.base/share/native/libjava/jni_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ void* getProcessHandle();
void buildJniFunctionName(const char *sym, const char *cname,
char *jniEntryName);

#ifdef _AIX
void* findEntryInProcess(const char* name);
#endif /* _AIX */
#if defined(_AIX)
void *findEntryInProcess(const char *name);
#endif /* defined(_AIX) */

JNIEXPORT size_t JNICALL
getLastErrorString(char *buf, size_t len);
Expand Down
7 changes: 4 additions & 3 deletions src/java.base/unix/native/libjava/jni_util_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ void buildJniFunctionName(const char *sym, const char *cname,
}
}

#ifdef _AIX
void* findEntryInProcess(const char* name) {
#if defined(_AIX)
void *findEntryInProcess(const char *name)
{
return JVM_FindLibraryEntry(RTLD_DEFAULT, name);
}
#endif /* _AIX */
#endif /* defined(_AIX) */

JNIEXPORT size_t JNICALL
getLastErrorString(char *buf, size_t len)
Expand Down
14 changes: 11 additions & 3 deletions test/jdk/java/foreign/NativeTestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
*
*/

/*
* ===========================================================================
* (c) Copyright IBM Corp. 2022, 2022 All Rights Reserved
* ===========================================================================
*/

import java.lang.foreign.Addressable;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.Linker;
Expand All @@ -34,6 +40,8 @@

public class NativeTestHelper {

private static final boolean isAixOS = System.getProperty("os.name").startsWith("AIX");

public static boolean isIntegral(MemoryLayout layout) {
return layout instanceof ValueLayout valueLayout && isIntegral(valueLayout.carrier());
}
Expand Down Expand Up @@ -69,19 +77,19 @@ public static boolean isPointer(MemoryLayout layout) {
/**
* The layout for the {@code long long} C type.
*/
public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG.withBitAlignment(64);
public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG.withBitAlignment(isAixOS ? 32 : 64);
/**
* The layout for the {@code float} C type
*/
public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT.withBitAlignment(32);
/**
* The layout for the {@code double} C type
*/
public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE.withBitAlignment(64);
public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE.withBitAlignment(isAixOS ? 32 : 64);
/**
* The {@code T*} native type.
*/
public static final ValueLayout.OfAddress C_POINTER = ValueLayout.ADDRESS.withBitAlignment(64);
public static final ValueLayout.OfAddress C_POINTER = ValueLayout.ADDRESS.withBitAlignment(isAixOS ? 32 : 64);

private static Linker LINKER = Linker.nativeLinker();

Expand Down

0 comments on commit 4e70209

Please sign in to comment.