X stringlengths 236 264k | y stringlengths 5 74 |
|---|---|
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
[MASK] argCalc = forUpcall ? new Box [MASK] (true) : new Unbox [MASK] (true, options.allowsHeapAccess());
[MASK] retCalc = forUpcall ? new Unbox [MASK] (false, false) : new Box [MASK] (false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class [MASK] {
protected final StorageCalculator storageCalculator;
protected [MASK] (boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class Unbox [MASK] extends [MASK] {
private final boolean useAddressPairs;
Unbox [MASK] (boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class Box [MASK] extends [MASK] {
Box [MASK] (boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for Box [MASK] , but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| BindingCalculator |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind. [MASK] Mapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket< [MASK] > b1 = redisson.getBucket("b1");
RBucket< [MASK] > b2 = redisson.getBucket("b2");
RBucket< [MASK] > b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket< [MASK] > b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket< [MASK] > b5 = redisson.getBucket("b5");
RLive [MASK] Service service = redisson.getLive [MASK] Service();
RedissonLive [MASK] ServiceTest.TestREntity rlo = new RedissonLive [MASK] ServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLive [MASK] );
Assertions.assertEquals("t1", ((RedissonLive [MASK] ServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLive [MASK] ServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync< [MASK] > b1 = batch.getBucket("b1");
RBucketAsync< [MASK] > b2 = batch.getBucket("b2");
RBucketAsync< [MASK] > b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync< [MASK] > b1 = batch.getBucket("b1");
RBucketAsync< [MASK] > b2 = batch.getBucket("b2");
RBucketAsync< [MASK] > b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket< [MASK] > b1 = redissonClient.getBucket("b1");
b1.set(new My [MASK] ());
RSet< [MASK] > s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<My [MASK] > b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof My [MASK] );
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class My [MASK] {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| Object |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi. [MASK] ;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses [MASK]
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
[MASK] csb = new [MASK] (CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| CallingSequenceBuilder |
/**
* Copyright (c) 2013-2024 Nikita Koksharov
*
* 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 org.redisson.hibernate.strategy;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.internal.DefaultCacheKeysFactory;
import org.hibernate.cache.spi.EntityRegion;
import org.hibernate.cache.spi.GeneralDataRegion;
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
import org.hibernate.cache.spi.access.SoftLock;
import org.hibernate.cfg.Settings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.redisson.hibernate.region.RedissonEntityRegion;
/**
*
* @author Nikita Koksharov
*
*/
public class ReadOnlyEntityRegionAccessStrategy extends BaseRegionAccessStrategy implements EntityRegionAccessStrategy {
public ReadOnlyEntityRegionAccessStrategy(Settings settings, GeneralDataRegion region) {
super(settings, region);
}
@Override
public Object get(SessionImplementor session, Object key, long txTimestamp) throws CacheException {
return region.get(session, key);
}
@Override
public boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object [MASK] , boolean minimalPutOverride)
throws CacheException {
if (minimalPutOverride && region.contains(key)) {
return false;
}
region.put(session, key, value);
return true;
}
@Override
public SoftLock lockItem(SessionImplementor session, Object key, Object [MASK] ) throws CacheException {
return null;
}
@Override
public void unlockItem(SessionImplementor session, Object key, SoftLock lock) throws CacheException {
evict(key);
}
@Override
public EntityRegion getRegion() {
return (EntityRegion) region;
}
@Override
public boolean insert(SessionImplementor session, Object key, Object value, Object [MASK] ) throws CacheException {
return false;
}
@Override
public boolean afterInsert(SessionImplementor session, Object key, Object value, Object [MASK] ) throws CacheException {
region.put(session, key, value);
return true;
}
@Override
public boolean update(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion)
throws CacheException {
throw new UnsupportedOperationException("Unable to update read-only object");
}
@Override
public boolean afterUpdate(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
throws CacheException {
throw new UnsupportedOperationException("Unable to update read-only object");
}
@Override
public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) {
return ((RedissonEntityRegion)region).getCacheKeysFactory().createEntityKey( id, persister, factory, tenantIdentifier );
}
@Override
public Object getCacheKeyId(Object cacheKey) {
return ((RedissonEntityRegion)region).getCacheKeysFactory().getEntityId(cacheKey);
}
}
| version |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new [MASK] ());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket< [MASK] > b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof [MASK] );
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class [MASK] {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| MyObject |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
[MASK] argumentClass = [MASK] .classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
[MASK] argumentClass = [MASK] .classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| TypeClass |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson. [MASK] ("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson. [MASK] ("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson. [MASK] ("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| getMapCache |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions. [MASK] (b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions. [MASK] (b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions. [MASK] (redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions. [MASK] (s1.add(b1));
Assertions. [MASK] (codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions. [MASK] (codec == b2.getCodec());
Assertions. [MASK] (b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| assertTrue |
/**
* Copyright (c) 2013-2024 Nikita Koksharov
*
* 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 org.redisson.hibernate.strategy;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.internal.DefaultCacheKeysFactory;
import org.hibernate.cache.spi.EntityRegion;
import org.hibernate.cache.spi.GeneralDataRegion;
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
import org.hibernate.cache.spi.access.SoftLock;
import org.hibernate.cfg.Settings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.redisson.hibernate.region. [MASK] ;
/**
*
* @author Nikita Koksharov
*
*/
public class ReadOnlyEntityRegionAccessStrategy extends BaseRegionAccessStrategy implements EntityRegionAccessStrategy {
public ReadOnlyEntityRegionAccessStrategy(Settings settings, GeneralDataRegion region) {
super(settings, region);
}
@Override
public Object get(SessionImplementor session, Object key, long txTimestamp) throws CacheException {
return region.get(session, key);
}
@Override
public boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException {
if (minimalPutOverride && region.contains(key)) {
return false;
}
region.put(session, key, value);
return true;
}
@Override
public SoftLock lockItem(SessionImplementor session, Object key, Object version) throws CacheException {
return null;
}
@Override
public void unlockItem(SessionImplementor session, Object key, SoftLock lock) throws CacheException {
evict(key);
}
@Override
public EntityRegion getRegion() {
return (EntityRegion) region;
}
@Override
public boolean insert(SessionImplementor session, Object key, Object value, Object version) throws CacheException {
return false;
}
@Override
public boolean afterInsert(SessionImplementor session, Object key, Object value, Object version) throws CacheException {
region.put(session, key, value);
return true;
}
@Override
public boolean update(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion)
throws CacheException {
throw new UnsupportedOperationException("Unable to update read-only object");
}
@Override
public boolean afterUpdate(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
throws CacheException {
throw new UnsupportedOperationException("Unable to update read-only object");
}
@Override
public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) {
return (( [MASK] )region).getCacheKeysFactory().createEntityKey( id, persister, factory, tenantIdentifier );
}
@Override
public Object getCacheKeyId(Object cacheKey) {
return (( [MASK] )region).getCacheKeysFactory().getEntityId(cacheKey);
}
}
| RedissonEntityRegion |
/*
* Copyright (c) 1998, 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.
*
* 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.
*/
/* @test
@bug 4092350
@summary Verify that reads and writes of primitives are correct
*/
// The bug mentioned is actually a performance bug that prompted
// changes in the methods to write primitives
import java.io.*;
import java.io.*;
public class ReadWritePrimitives {
public static void main(String args[]) throws [MASK] {
long start, finish;
start = System.currentTimeMillis();
testShort();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
start = System.currentTimeMillis();
testChar();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
start = System.currentTimeMillis();
testInt();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
start = System.currentTimeMillis();
testLong();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
}
private static void testShort() throws [MASK] {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeShort((short)i);
}
f.writeShort((short)65535);
f.close();
f = new RandomAccessFile(fh,"r");
for(int i = 0; i < 10000; i++) {
short r = f.readShort();
if (r != ((short)i)) {
System.err.println("An error occurred. Read:" + r
+ " i:" + ((short)i));
throw new [MASK] ("Bad read from a writeShort");
}
}
short rmax = f.readShort();
if (rmax != ((short)65535)) {
System.err.println("An error occurred. Read:" + rmax);
throw new [MASK] ("Bad read from a writeShort");
}
f.close();
}
private static void testChar() throws [MASK] {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeChar((char)i);
}
f.close();
f = new RandomAccessFile(fh,"r");
for(int i = 0; i < 10000; i++) {
char r = f.readChar();
if (r != ((char)i)){
System.err.println("An error occurred. Read:" + r
+ " i:" + ((char) i));
throw new [MASK] ("Bad read from a writeChar");
}
}
f.close();
}
private static void testInt() throws [MASK] {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeInt((short)i);
}
f.writeInt(Integer.MAX_VALUE);
f.close();
f = new RandomAccessFile(fh, "r");
for(int i = 0; i < 10000; i++) {
int r = f.readInt();
if (r != i){
System.err.println("An error occurred. Read:" + r
+ " i:" + i);
throw new [MASK] ("Bad read from a writeInt");
}
}
int rmax = f.readInt();
if (rmax != Integer.MAX_VALUE){
System.err.println("An error occurred. Read:" + rmax);
throw new [MASK] ("Bad read from a writeInt");
}
f.close();
}
private static void testLong() throws [MASK] {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeLong(123456789L * (long)i);
}
f.close();
f = new RandomAccessFile(fh,"r");
for(int i = 0; i < 10000; i++){
long r = f.readLong();
if (r != (((long) i) * 123456789L) ) {
System.err.println("An error occurred. Read:" + r
+ " i" + ((long) i));
throw new [MASK] ("Bad read from a writeInt");
}
}
f.close();
}
}
| IOException |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence [MASK] , boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings. [MASK] ).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings. [MASK] );
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings. [MASK] );
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| callingSequence |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int [MASK] = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + [MASK] ) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += [MASK] ;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| fpRegCnt |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke. [MASK] ;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings( [MASK] mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings( [MASK] mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall( [MASK] mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall( [MASK] mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| MethodType |
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* 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 org.jkiss.dbeaver.tools.transfer.stream;
import org.jkiss.code. [MASK] ;
import java.io.IOException;
import java.io.OutputStream;
public class StatOutputStream extends OutputStream {
private final OutputStream stream;
private long bytesWritten = 0;
public StatOutputStream(OutputStream stream) {
this.stream = stream;
}
public long getBytesWritten() {
return bytesWritten;
}
@Override
public void write(int b) throws IOException {
stream.write(b);
bytesWritten++;
}
@Override
public void write(@ [MASK] byte[] b) throws IOException {
stream.write(b);
bytesWritten += b.length;
}
@Override
public void write(@ [MASK] byte[] b, int off, int len) throws IOException {
stream.write(b, off, len);
bytesWritten += len;
}
@Override
public void flush() throws IOException {
stream.flush();
}
@Override
public void close() throws IOException {
stream.close();
}
}
| NotNull |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage [MASK] (int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator. [MASK] (StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator. [MASK] (StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator. [MASK] (StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator. [MASK] (StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator. [MASK] (StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator. [MASK] (StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator. [MASK] (StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator. [MASK] (StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator. [MASK] (StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator. [MASK] (StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator. [MASK] (StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator. [MASK] (StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| getStorage |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap< [MASK] , RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry< [MASK] , RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket< [MASK] >> b1 = redisson.getSet("set");
RBucket< [MASK] > b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket< [MASK] >> b1 = redisson.getScoredSortedSet("set");
RBucket< [MASK] > b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket< [MASK] >>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket< [MASK] >> b1 = redisson.getSetCache("set");
RBucket< [MASK] > b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache< [MASK] , RSetCache<RBucket< [MASK] >>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket< [MASK] >, RSetCache<RBucket< [MASK] >>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket< [MASK] >> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket< [MASK] >> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket< [MASK] >> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket< [MASK] >> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket< [MASK] >> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap< [MASK] , RBucket< [MASK] >> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket< [MASK] >, RBucket< [MASK] >> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap< [MASK] , RSetCache<RBucket< [MASK] >>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket< [MASK] >, RSetCache<RBucket< [MASK] >>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket< [MASK] >> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket< [MASK] >> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap< [MASK] , RBucket< [MASK] >> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket< [MASK] >, RBucket< [MASK] >> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap< [MASK] , RBucket< [MASK] >> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket< [MASK] >, RBucket< [MASK] >> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private [MASK] name;
public [MASK] getName() {
return name;
}
public void setName( [MASK] name) {
this.name = name;
}
}
}
| String |
/*
* Copyright (c) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockitousage.puzzlers;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import org.junit.Test;
import org.mockito.exceptions.verification.WantedButNotInvoked;
import org.mockitoutil.TestBase;
public class OverloadingPuzzleTest extends TestBase {
private Super mock;
private void setMockWithDowncast(Super mock) {
this.mock = mock;
}
private interface Super {
void say(Object [MASK] );
}
private interface Sub extends Super {
void say(String [MASK] );
}
private void say(Object [MASK] ) {
mock.say( [MASK] );
}
@Test
public void shouldUseArgumentTypeWhenOverloadingPuzzleDetected() throws Exception {
Sub sub = mock(Sub.class);
setMockWithDowncast(sub);
say("Hello");
try {
verify(sub).say("Hello");
fail();
} catch (WantedButNotInvoked e) {
}
}
}
| message |
package org. [MASK] ;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org. [MASK] .api.*;
import org. [MASK] .client.codec.Codec;
import org. [MASK] .client.protocol.ScoredEntry;
import org. [MASK] .codec.JsonJacksonCodec;
import org. [MASK] .codec.Kryo5Codec;
import org. [MASK] .config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = [MASK] .getMap("data-00");
RBitSet bs = [MASK] .getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = [MASK] .getBucket("b1");
RBucket<Object> b2 = [MASK] .getBucket("b2");
RBucket<Object> b3 = [MASK] .getBucket("b3");
b2.set(b3);
b1.set( [MASK] .getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = [MASK] .getBucket("b4");
b4.set( [MASK] .getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = [MASK] .getBucket("b5");
RLiveObjectService service = [MASK] .getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue( [MASK] .getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) [MASK] .getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) [MASK] .getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = [MASK] .createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = [MASK] .createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = [MASK] .createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = [MASK] .reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = [MASK] .getSet("set");
RBucket<String> b2 = [MASK] .getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, [MASK] .getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = [MASK] .getScoredSortedSet("set");
RBucket<String> b2 = [MASK] .getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, [MASK] .getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = [MASK] .getSetCache("set");
RBucket<String> b2 = [MASK] .getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, [MASK] .getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = [MASK] .getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = [MASK] .getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = [MASK] .getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = [MASK] .getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = [MASK] .getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = [MASK] .getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = [MASK] .getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = [MASK] .getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = [MASK] .getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = [MASK] .getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = [MASK] .getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = [MASK] .getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = [MASK] .getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = [MASK] .getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = [MASK] .getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = [MASK] .getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = [MASK] .getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = [MASK] .getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = [MASK] .getMap("set");
RBucket<RMap> b1 = [MASK] .getBucket("bucket1");
RBucket<RMap> b2 = [MASK] .getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, [MASK] .getKeys().count());
Assertions.assertEquals(1, [MASK] .getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, [MASK] .getKeys().count());
Assertions.assertEquals(3, [MASK] .getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress( [MASK] .getConfig().useSingleServer().getAddress());
RedissonClient [MASK] Client = Redisson.create(config);
RBucket<Object> b1 = [MASK] Client.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = [MASK] Client.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient [MASK] Client1 = Redisson.create(config);
RSet<RBucket> s2 = [MASK] Client1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
[MASK] Client.shutdown();
[MASK] Client1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| redisson |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean [MASK] ) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = [MASK] (cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings. [MASK] ) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings. [MASK] , dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean [MASK] (Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| isInMemoryReturn |
package me.chanjar.weixin.open.bean.result;
import com.google.gson.annotations. [MASK] ;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = true)
public class WxOpenRegisterBetaWeappResult extends WxOpenResult {
@ [MASK] ("authorize_url")
private String authorizeUrl;
@ [MASK] ("unique_id")
protected String uniqueId;
}
| SerializedName |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings [MASK] (MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return [MASK] (mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings [MASK] (MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc. [MASK] (carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc. [MASK] (carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc. [MASK] (carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = [MASK] (mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = [MASK] (mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> [MASK] (Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> [MASK] (Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> [MASK] (Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| getBindings |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb. [MASK] (), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding. [MASK] er();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings. [MASK] ();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding. [MASK] er();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings. [MASK] ();
}
}
}
| build |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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 " [MASK] path" 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
[MASK] <?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
[MASK] <?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
[MASK] <?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings( [MASK] <?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings( [MASK] <?> carrier, MemoryLayout layout) {
Type [MASK] argument [MASK] = Type [MASK] .classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argument [MASK] ) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
[MASK] <?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
[MASK] <?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argument [MASK] );
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings( [MASK] <?> carrier, MemoryLayout layout) {
Type [MASK] argument [MASK] = Type [MASK] .classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argument [MASK] ) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
[MASK] <?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
[MASK] <?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argument [MASK] );
}
return bindings.build();
}
}
}
| Class |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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. [MASK] .foreign.abi.s390.linux;
import jdk. [MASK] .foreign.Utils;
import jdk. [MASK] .foreign.abi.ABIDescriptor;
import jdk. [MASK] .foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk. [MASK] .foreign.abi.Binding;
import jdk. [MASK] .foreign.abi.CallingSequence;
import jdk. [MASK] .foreign.abi.CallingSequenceBuilder;
import jdk. [MASK] .foreign.abi.DowncallLinker;
import jdk. [MASK] .foreign.abi.LinkerOptions;
import jdk. [MASK] .foreign.abi.SharedUtils;
import jdk. [MASK] .foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk. [MASK] .foreign.abi.s390.S390Architecture.*;
import static jdk. [MASK] .foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| internal |
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* 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 org. [MASK] .dbeaver.tools.transfer.stream.model;
import org. [MASK] .code.NotNull;
import org. [MASK] .code.Nullable;
import org. [MASK] .dbeaver.DBException;
import org. [MASK] .dbeaver.model.DBPDataSource;
import org. [MASK] .dbeaver.model.DBPDataSourceInfo;
import org. [MASK] .dbeaver.model.data.DBDFormatSettings;
import org. [MASK] .dbeaver.model.data.DBDValueHandler;
import org. [MASK] .dbeaver.model.data.DBDValueHandlerProvider;
import org. [MASK] .dbeaver.model.exec.DBCExecutionContext;
import org. [MASK] .dbeaver.model.impl.AbstractSimpleDataSource;
import org. [MASK] .dbeaver.model.impl.data.DefaultValueHandler;
import org. [MASK] .dbeaver.model.runtime.DBRProgressMonitor;
import org. [MASK] .dbeaver.model.sql.SQLDialect;
import org. [MASK] .dbeaver.model.struct.DBSObject;
import org. [MASK] .dbeaver.model.struct.DBSTypedObject;
import java.util.Collection;
/**
* Stream data source. It is a fake client-side datasource to emulate database-like data producers.
*/
public class StreamDataSource extends AbstractSimpleDataSource<StreamExecutionContext> implements DBDValueHandlerProvider {
private final StreamDataSourceDialect dialect;
public StreamDataSource(StreamDataSourceContainer container) {
super(container);
this.executionContext = new StreamExecutionContext(this, "Main");
this.dialect = new StreamDataSourceDialect();
}
public StreamDataSource(String inputName) {
this(new StreamDataSourceContainer(inputName));
}
@NotNull
@Override
public DBPDataSourceInfo getInfo() {
return new StreamDataSourceInfo();
}
@NotNull
@Override
public SQLDialect getSQLDialect() {
return dialect;
}
@Override
public void initialize(@NotNull DBRProgressMonitor monitor) throws DBException {
}
@NotNull
@Override
public StreamExecutionContext openIsolatedContext(@NotNull DBRProgressMonitor monitor, @NotNull String purpose, @Nullable DBCExecutionContext initFrom) throws DBException {
return new StreamExecutionContext(this, purpose);
}
// We need to implement value handler provider to pass default value handler for attribute bindings
@Nullable
@Override
public DBDValueHandler getValueHandler(DBPDataSource dataSource, DBDFormatSettings preferences, DBSTypedObject typedObject) {
return DefaultValueHandler.INSTANCE;
}
@Override
public Collection<? extends DBSObject> getChildren(@NotNull DBRProgressMonitor monitor) throws DBException {
return null;
}
@Nullable
@Override
public DBSObject getChild(@NotNull DBRProgressMonitor monitor, @NotNull String childName) throws DBException {
return null;
}
@NotNull
@Override
public Class<? extends DBSObject> getPrimaryChildType(@Nullable DBRProgressMonitor monitor) throws DBException {
return DBSObject.class;
}
@Override
public void cacheStructure(@NotNull DBRProgressMonitor monitor, int scope) throws DBException {
}
}
| jkiss |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent. [MASK] ;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, [MASK] .MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, [MASK] .MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, [MASK] .MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| TimeUnit |
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* 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 org.jkiss.dbeaver.tools.transfer.stream;
import org.jkiss.code.NotNull;
import java.io.IOException;
import java.io.OutputStream;
public class StatOutputStream extends OutputStream {
private final OutputStream stream;
private long [MASK] = 0;
public StatOutputStream(OutputStream stream) {
this.stream = stream;
}
public long getBytesWritten() {
return [MASK] ;
}
@Override
public void write(int b) throws IOException {
stream.write(b);
[MASK] ++;
}
@Override
public void write(@NotNull byte[] b) throws IOException {
stream.write(b);
[MASK] += b.length;
}
@Override
public void write(@NotNull byte[] b, int off, int len) throws IOException {
stream.write(b, off, len);
[MASK] += len;
}
@Override
public void flush() throws IOException {
stream.flush();
}
@Override
public void close() throws IOException {
stream.close();
}
}
| bytesWritten |
/*
* Copyright 1999-2020 Alibaba Group Holding Ltd.
*
* 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.alibaba.nacos.naming.push.v2;
import com.alibaba.nacos.common.event.ServerConfigChangeEvent;
import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.naming.constants.PushConstants;
import com.alibaba.nacos.sys.env.EnvUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.mock.env.MockEnvironment;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertEquals;
class PushConfigTest {
private PushConfig pushConfig;
private MockEnvironment mockEnvironment;
private long pushTaskDelay = PushConstants.DEFAULT_PUSH_TASK_DELAY * 2;
private long pushTaskTimeout = PushConstants.DEFAULT_PUSH_TASK_TIMEOUT * 2;
private long pushTaskRetryDelay = PushConstants.DEFAULT_PUSH_TASK_RETRY_DELAY * 2;
@BeforeEach
void setUp() throws Exception {
mockEnvironment = new MockEnvironment();
EnvUtil.setEnvironment(mockEnvironment);
pushConfig = PushConfig.getInstance();
}
@Test
void testUpgradeConfig() throws InterruptedException {
mockEnvironment. [MASK] (PushConstants.PUSH_TASK_DELAY, String.valueOf(pushTaskDelay));
mockEnvironment. [MASK] (PushConstants.PUSH_TASK_TIMEOUT, String.valueOf(pushTaskTimeout));
mockEnvironment. [MASK] (PushConstants.PUSH_TASK_RETRY_DELAY, String.valueOf(pushTaskRetryDelay));
NotifyCenter.publishEvent(ServerConfigChangeEvent.newEvent());
TimeUnit.SECONDS.sleep(1);
assertEquals(pushTaskDelay, pushConfig.getPushTaskDelay());
assertEquals(pushTaskTimeout, pushConfig.getPushTaskTimeout());
assertEquals(pushTaskRetryDelay, pushConfig.getPushTaskRetryDelay());
}
@Test
void testInitConfigFormEnv() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
mockEnvironment. [MASK] (PushConstants.PUSH_TASK_DELAY, String.valueOf(pushTaskDelay));
mockEnvironment. [MASK] (PushConstants.PUSH_TASK_TIMEOUT, String.valueOf(pushTaskTimeout));
mockEnvironment. [MASK] (PushConstants.PUSH_TASK_RETRY_DELAY, String.valueOf(pushTaskRetryDelay));
Constructor<PushConfig> declaredConstructor = PushConfig.class.getDeclaredConstructor();
declaredConstructor.setAccessible(true);
PushConfig pushConfig = declaredConstructor.newInstance();
assertEquals(pushTaskDelay, pushConfig.getPushTaskDelay());
assertEquals(pushTaskTimeout, pushConfig.getPushTaskTimeout());
assertEquals(pushTaskRetryDelay, pushConfig.getPushTaskRetryDelay());
}
}
| setProperty |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson. [MASK] ("b1");
RBucket<Object> b2 = redisson. [MASK] ("b2");
RBucket<Object> b3 = redisson. [MASK] ("b3");
b2.set(b3);
b1.set(redisson. [MASK] ("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson. [MASK] ("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson. [MASK] ("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson. [MASK] ("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson. [MASK] ("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson. [MASK] ("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch. [MASK] ("b1");
RBucketAsync<Object> b2 = batch. [MASK] ("b2");
RBucketAsync<Object> b3 = batch. [MASK] ("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch. [MASK] ("b1").getAsync();
batch. [MASK] ("b2").getAsync();
batch. [MASK] ("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch. [MASK] ("b1");
RBucketAsync<Object> b2 = batch. [MASK] ("b2");
RBucketAsync<Object> b3 = batch. [MASK] ("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b. [MASK] ("b1").get();
b. [MASK] ("b2").get();
b. [MASK] ("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson. [MASK] ("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson. [MASK] ("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson. [MASK] ("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson. [MASK] ("bucket1");
RBucket<RMap> b2 = redisson. [MASK] ("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient. [MASK] ("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| getBucket |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry. [MASK] ().get(5)).isTrue();
assertThat(entry. [MASK] ().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()). [MASK] ());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next(). [MASK] ().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next(). [MASK] ().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next(). [MASK] ().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next(). [MASK] ().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next(). [MASK] ().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| getValue |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> [MASK] = b1. [MASK] (0, 1);
Assertions.assertEquals(b2.get(), [MASK] .iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| entryRange |
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* 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 org.jkiss.dbeaver.tools.transfer.stream.model;
import org.jkiss.code.NotNull;
import org.jkiss.code. [MASK] ;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDataSourceInfo;
import org.jkiss.dbeaver.model.data.DBDFormatSettings;
import org.jkiss.dbeaver.model.data.DBDValueHandler;
import org.jkiss.dbeaver.model.data.DBDValueHandlerProvider;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.impl.AbstractSimpleDataSource;
import org.jkiss.dbeaver.model.impl.data.DefaultValueHandler;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLDialect;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import java.util.Collection;
/**
* Stream data source. It is a fake client-side datasource to emulate database-like data producers.
*/
public class StreamDataSource extends AbstractSimpleDataSource<StreamExecutionContext> implements DBDValueHandlerProvider {
private final StreamDataSourceDialect dialect;
public StreamDataSource(StreamDataSourceContainer container) {
super(container);
this.executionContext = new StreamExecutionContext(this, "Main");
this.dialect = new StreamDataSourceDialect();
}
public StreamDataSource(String inputName) {
this(new StreamDataSourceContainer(inputName));
}
@NotNull
@Override
public DBPDataSourceInfo getInfo() {
return new StreamDataSourceInfo();
}
@NotNull
@Override
public SQLDialect getSQLDialect() {
return dialect;
}
@Override
public void initialize(@NotNull DBRProgressMonitor monitor) throws DBException {
}
@NotNull
@Override
public StreamExecutionContext openIsolatedContext(@NotNull DBRProgressMonitor monitor, @NotNull String purpose, @ [MASK] DBCExecutionContext initFrom) throws DBException {
return new StreamExecutionContext(this, purpose);
}
// We need to implement value handler provider to pass default value handler for attribute bindings
@ [MASK]
@Override
public DBDValueHandler getValueHandler(DBPDataSource dataSource, DBDFormatSettings preferences, DBSTypedObject typedObject) {
return DefaultValueHandler.INSTANCE;
}
@Override
public Collection<? extends DBSObject> getChildren(@NotNull DBRProgressMonitor monitor) throws DBException {
return null;
}
@ [MASK]
@Override
public DBSObject getChild(@NotNull DBRProgressMonitor monitor, @NotNull String childName) throws DBException {
return null;
}
@NotNull
@Override
public Class<? extends DBSObject> getPrimaryChildType(@ [MASK] DBRProgressMonitor monitor) throws DBException {
return DBSObject.class;
}
@Override
public void cacheStructure(@NotNull DBRProgressMonitor monitor, int scope) throws DBException {
}
}
| Nullable |
/*
* Copyright 1999-2020 Alibaba Group Holding Ltd.
*
* 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.alibaba. [MASK] .naming.push.v2;
import com.alibaba. [MASK] .common.event.ServerConfigChangeEvent;
import com.alibaba. [MASK] .common.notify.NotifyCenter;
import com.alibaba. [MASK] .naming.constants.PushConstants;
import com.alibaba. [MASK] .sys.env.EnvUtil;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.mock.env.MockEnvironment;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertEquals;
class PushConfigTest {
private PushConfig pushConfig;
private MockEnvironment mockEnvironment;
private long pushTaskDelay = PushConstants.DEFAULT_PUSH_TASK_DELAY * 2;
private long pushTaskTimeout = PushConstants.DEFAULT_PUSH_TASK_TIMEOUT * 2;
private long pushTaskRetryDelay = PushConstants.DEFAULT_PUSH_TASK_RETRY_DELAY * 2;
@BeforeEach
void setUp() throws Exception {
mockEnvironment = new MockEnvironment();
EnvUtil.setEnvironment(mockEnvironment);
pushConfig = PushConfig.getInstance();
}
@Test
void testUpgradeConfig() throws InterruptedException {
mockEnvironment.setProperty(PushConstants.PUSH_TASK_DELAY, String.valueOf(pushTaskDelay));
mockEnvironment.setProperty(PushConstants.PUSH_TASK_TIMEOUT, String.valueOf(pushTaskTimeout));
mockEnvironment.setProperty(PushConstants.PUSH_TASK_RETRY_DELAY, String.valueOf(pushTaskRetryDelay));
NotifyCenter.publishEvent(ServerConfigChangeEvent.newEvent());
TimeUnit.SECONDS.sleep(1);
assertEquals(pushTaskDelay, pushConfig.getPushTaskDelay());
assertEquals(pushTaskTimeout, pushConfig.getPushTaskTimeout());
assertEquals(pushTaskRetryDelay, pushConfig.getPushTaskRetryDelay());
}
@Test
void testInitConfigFormEnv() throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
mockEnvironment.setProperty(PushConstants.PUSH_TASK_DELAY, String.valueOf(pushTaskDelay));
mockEnvironment.setProperty(PushConstants.PUSH_TASK_TIMEOUT, String.valueOf(pushTaskTimeout));
mockEnvironment.setProperty(PushConstants.PUSH_TASK_RETRY_DELAY, String.valueOf(pushTaskRetryDelay));
Constructor<PushConfig> declaredConstructor = PushConfig.class.getDeclaredConstructor();
declaredConstructor.setAccessible(true);
PushConfig pushConfig = declaredConstructor.newInstance();
assertEquals(pushTaskDelay, pushConfig.getPushTaskDelay());
assertEquals(pushTaskTimeout, pushConfig.getPushTaskTimeout());
assertEquals(pushTaskRetryDelay, pushConfig.getPushTaskRetryDelay());
}
}
| nacos |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson. [MASK] ("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson. [MASK] ("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson. [MASK] ("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson. [MASK] ("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| getLocalCachedMap |
package com.gateway.web.rest.errors;
import com.gateway.IntegrationTest;
import org.hamcrest.core.AnyOf;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.http.HttpStatus;
import org.springframework.http. [MASK] ;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* Integration tests {@link ExceptionTranslator} controller advice.
*/
@WithMockUser
@AutoConfigureWebTestClient(timeout = IntegrationTest.DEFAULT_TIMEOUT)
@IntegrationTest
class ExceptionTranslatorIT {
@Autowired
private WebTestClient webTestClient;
@Test
void testConcurrencyFailure() {
webTestClient
.get()
.uri("/api/exception-translator-test/concurrency-failure")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.CONFLICT)
.expectHeader()
.contentType( [MASK] .APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo(ErrorConstants.ERR_CONCURRENCY_FAILURE);
}
@Test
void testMethodArgumentNotValid() {
webTestClient
.post()
.uri("/api/exception-translator-test/method-argument")
.contentType( [MASK] .APPLICATION_JSON)
.bodyValue("{}")
.exchange()
.expectHeader()
.contentType( [MASK] .APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo(ErrorConstants.ERR_VALIDATION)
.jsonPath("$.fieldErrors.[0].objectName")
.isEqualTo("test")
.jsonPath("$.fieldErrors.[0].field")
.isEqualTo("test")
.jsonPath("$.fieldErrors.[0].message")
.isEqualTo("must not be null");
}
@Test
void testMissingRequestPart() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-part")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType( [MASK] .APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400");
}
@Test
void testMissingRequestParameter() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-parameter")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType( [MASK] .APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400");
}
@Test
void testAccessDenied() {
webTestClient
.get()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isForbidden()
.expectHeader()
.contentType( [MASK] .APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.403")
.jsonPath("$.detail")
.isEqualTo("test access denied!");
}
@Test
void testUnauthorized() {
webTestClient
.get()
.uri("/api/exception-translator-test/unauthorized")
.exchange()
.expectStatus()
.isUnauthorized()
.expectHeader()
.contentType( [MASK] .APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.401")
.jsonPath("$.path")
.isEqualTo("/api/exception-translator-test/unauthorized")
.jsonPath("$.detail")
.value(AnyOf.anyOf(IsEqual.equalTo("test authentication failed!"), IsEqual.equalTo("Invalid credentials")));
}
@Test
void testMethodNotSupported() {
webTestClient
.post()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.METHOD_NOT_ALLOWED)
.expectHeader()
.contentType( [MASK] .APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.405")
.jsonPath("$.detail")
.isEqualTo("405 METHOD_NOT_ALLOWED \"Request method 'POST' is not supported.\"");
}
@Test
void testExceptionWithResponseStatus() {
webTestClient
.get()
.uri("/api/exception-translator-test/response-status")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType( [MASK] .APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400")
.jsonPath("$.title")
.isEqualTo("test response status");
}
@Test
void testInternalServerError() {
webTestClient
.get()
.uri("/api/exception-translator-test/internal-server-error")
.exchange()
.expectHeader()
.contentType( [MASK] .APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.500")
.jsonPath("$.title")
.isEqualTo("Internal Server Error");
}
}
| MediaType |
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* 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 org.jkiss.dbeaver.tools.transfer.stream;
import org.jkiss.code.NotNull;
import java.io.IOException;
import java.io. [MASK] ;
public class Stat [MASK] extends [MASK] {
private final [MASK] stream;
private long bytesWritten = 0;
public Stat [MASK] ( [MASK] stream) {
this.stream = stream;
}
public long getBytesWritten() {
return bytesWritten;
}
@Override
public void write(int b) throws IOException {
stream.write(b);
bytesWritten++;
}
@Override
public void write(@NotNull byte[] b) throws IOException {
stream.write(b);
bytesWritten += b.length;
}
@Override
public void write(@NotNull byte[] b, int off, int len) throws IOException {
stream.write(b, off, len);
bytesWritten += len;
}
@Override
public void flush() throws IOException {
stream.flush();
}
@Override
public void close() throws IOException {
stream.close();
}
}
| OutputStream |
package com.baeldung.kafka.admin;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers. [MASK] ;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import java.util.Properties;
import static org.assertj.core.api.Assertions.assertThat;
// This live test needs a running Docker instance so that a kafka container can be created
@Testcontainers
class KafkaTopicApplicationLiveTest {
@Container
private static final [MASK] KAFKA_CONTAINER = new [MASK] (DockerImageName.parse("confluentinc/cp-kafka:5.4.3"));
private KafkaTopicApplication kafkaTopicApplication;
@BeforeEach
void setup() {
Properties properties = new Properties();
properties.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, KAFKA_CONTAINER.getBootstrapServers());
kafkaTopicApplication = new KafkaTopicApplication(properties);
}
@Test
void givenTopicName_whenCreateNewTopic_thenTopicIsCreated() throws Exception {
kafkaTopicApplication.createTopic("test-topic");
String topicCommand = "/usr/bin/kafka-topics --bootstrap-server=localhost:9092 --list";
String stdout = KAFKA_CONTAINER.execInContainer("/bin/sh", "-c", topicCommand)
.getStdout();
assertThat(stdout).contains("test-topic");
}
}
| KafkaContainer |
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* 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 org.jkiss.dbeaver.tools.transfer.stream. [MASK] ;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver. [MASK] .DBPDataSource;
import org.jkiss.dbeaver. [MASK] .DBPDataSourceInfo;
import org.jkiss.dbeaver. [MASK] .data.DBDFormatSettings;
import org.jkiss.dbeaver. [MASK] .data.DBDValueHandler;
import org.jkiss.dbeaver. [MASK] .data.DBDValueHandlerProvider;
import org.jkiss.dbeaver. [MASK] .exec.DBCExecutionContext;
import org.jkiss.dbeaver. [MASK] .impl.AbstractSimpleDataSource;
import org.jkiss.dbeaver. [MASK] .impl.data.DefaultValueHandler;
import org.jkiss.dbeaver. [MASK] .runtime.DBRProgressMonitor;
import org.jkiss.dbeaver. [MASK] .sql.SQLDialect;
import org.jkiss.dbeaver. [MASK] .struct.DBSObject;
import org.jkiss.dbeaver. [MASK] .struct.DBSTypedObject;
import java.util.Collection;
/**
* Stream data source. It is a fake client-side datasource to emulate database-like data producers.
*/
public class StreamDataSource extends AbstractSimpleDataSource<StreamExecutionContext> implements DBDValueHandlerProvider {
private final StreamDataSourceDialect dialect;
public StreamDataSource(StreamDataSourceContainer container) {
super(container);
this.executionContext = new StreamExecutionContext(this, "Main");
this.dialect = new StreamDataSourceDialect();
}
public StreamDataSource(String inputName) {
this(new StreamDataSourceContainer(inputName));
}
@NotNull
@Override
public DBPDataSourceInfo getInfo() {
return new StreamDataSourceInfo();
}
@NotNull
@Override
public SQLDialect getSQLDialect() {
return dialect;
}
@Override
public void initialize(@NotNull DBRProgressMonitor monitor) throws DBException {
}
@NotNull
@Override
public StreamExecutionContext openIsolatedContext(@NotNull DBRProgressMonitor monitor, @NotNull String purpose, @Nullable DBCExecutionContext initFrom) throws DBException {
return new StreamExecutionContext(this, purpose);
}
// We need to implement value handler provider to pass default value handler for attribute bindings
@Nullable
@Override
public DBDValueHandler getValueHandler(DBPDataSource dataSource, DBDFormatSettings preferences, DBSTypedObject typedObject) {
return DefaultValueHandler.INSTANCE;
}
@Override
public Collection<? extends DBSObject> getChildren(@NotNull DBRProgressMonitor monitor) throws DBException {
return null;
}
@Nullable
@Override
public DBSObject getChild(@NotNull DBRProgressMonitor monitor, @NotNull String childName) throws DBException {
return null;
}
@NotNull
@Override
public Class<? extends DBSObject> getPrimaryChildType(@Nullable DBRProgressMonitor monitor) throws DBException {
return DBSObject.class;
}
@Override
public void cacheStructure(@NotNull DBRProgressMonitor monitor, int scope) throws DBException {
}
}
| model |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()). [MASK] ());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)). [MASK] ());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()). [MASK] ());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0). [MASK] ());
Assertions.assertEquals("b3", result.get(1). [MASK] ());
Assertions.assertEquals("b1", result.get(2). [MASK] ());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0). [MASK] ());
Assertions.assertEquals("b3", result.get(1). [MASK] ());
Assertions.assertEquals("b1", result.get(2). [MASK] ());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String [MASK] () {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| getName |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client. [MASK] .Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson. [MASK] .JsonJacksonCodec;
import org.redisson. [MASK] .Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec [MASK] = new Kryo5Codec();
config.setCodec( [MASK] );
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue( [MASK] == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue( [MASK] == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| codec |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3. [MASK] ().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1. [MASK] ().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1. [MASK] ().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3. [MASK] ().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| readAllValues |
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* 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 org.jkiss.dbeaver.tools.transfer.stream.model;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDataSourceInfo;
import org.jkiss.dbeaver.model.data.DBDFormatSettings;
import org.jkiss.dbeaver.model.data.DBDValueHandler;
import org.jkiss.dbeaver.model.data.DBDValueHandlerProvider;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.impl.AbstractSimpleDataSource;
import org.jkiss.dbeaver.model.impl.data.DefaultValueHandler;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLDialect;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import java.util.Collection;
/**
* Stream data source. It is a fake client-side datasource to emulate database-like data producers.
*/
public class StreamDataSource extends AbstractSimpleDataSource<StreamExecutionContext> implements DBDValueHandlerProvider {
private final StreamDataSourceDialect [MASK] ;
public StreamDataSource(StreamDataSourceContainer container) {
super(container);
this.executionContext = new StreamExecutionContext(this, "Main");
this. [MASK] = new StreamDataSourceDialect();
}
public StreamDataSource(String inputName) {
this(new StreamDataSourceContainer(inputName));
}
@NotNull
@Override
public DBPDataSourceInfo getInfo() {
return new StreamDataSourceInfo();
}
@NotNull
@Override
public SQLDialect getSQLDialect() {
return [MASK] ;
}
@Override
public void initialize(@NotNull DBRProgressMonitor monitor) throws DBException {
}
@NotNull
@Override
public StreamExecutionContext openIsolatedContext(@NotNull DBRProgressMonitor monitor, @NotNull String purpose, @Nullable DBCExecutionContext initFrom) throws DBException {
return new StreamExecutionContext(this, purpose);
}
// We need to implement value handler provider to pass default value handler for attribute bindings
@Nullable
@Override
public DBDValueHandler getValueHandler(DBPDataSource dataSource, DBDFormatSettings preferences, DBSTypedObject typedObject) {
return DefaultValueHandler.INSTANCE;
}
@Override
public Collection<? extends DBSObject> getChildren(@NotNull DBRProgressMonitor monitor) throws DBException {
return null;
}
@Nullable
@Override
public DBSObject getChild(@NotNull DBRProgressMonitor monitor, @NotNull String childName) throws DBException {
return null;
}
@NotNull
@Override
public Class<? extends DBSObject> getPrimaryChildType(@Nullable DBRProgressMonitor monitor) throws DBException {
return DBSObject.class;
}
@Override
public void cacheStructure(@NotNull DBRProgressMonitor monitor, int scope) throws DBException {
}
}
| dialect |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils. [MASK] (layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils. [MASK] (layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils. [MASK] (layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils. [MASK] (layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| primitiveCarrierForSize |
/*
* Copyright (c) 2015, 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.
*
* 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.
*/
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.util.Properties;
/*
* @test
* @bug 8073214 8075362
* @summary Tests to verify that load() and store() throw NPEs as advertised.
*/
public class LoadAndStoreNPE
{
public static void main(String[] args) throws Exception
{
int [MASK] = 0;
Properties props = new Properties();
try {
props.store((OutputStream)null, "comments");
[MASK] ++;
} catch (NullPointerException e) {
// do nothing
}
try {
props.store((Writer)null, "comments");
[MASK] ++;
} catch (NullPointerException e) {
// do nothing
}
try {
props.load((InputStream)null);
[MASK] ++;
} catch (NullPointerException e) {
// do nothing
}
try {
props.load((Reader)null);
[MASK] ++;
} catch (NullPointerException e) {
// do nothing
}
if ( [MASK] != 0) {
throw new RuntimeException("LoadAndStoreNPE failed with "
+ [MASK] + " errors!");
}
}
}
| failures |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", [MASK] .defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", [MASK] .defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", [MASK] .defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", [MASK] .defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| LocalCachedMapOptions |
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* 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 org.jkiss.dbeaver.tools.transfer.stream;
import org.jkiss.code.NotNull;
import java.io. [MASK] ;
import java.io.OutputStream;
public class StatOutputStream extends OutputStream {
private final OutputStream stream;
private long bytesWritten = 0;
public StatOutputStream(OutputStream stream) {
this.stream = stream;
}
public long getBytesWritten() {
return bytesWritten;
}
@Override
public void write(int b) throws [MASK] {
stream.write(b);
bytesWritten++;
}
@Override
public void write(@NotNull byte[] b) throws [MASK] {
stream.write(b);
bytesWritten += b.length;
}
@Override
public void write(@NotNull byte[] b, int off, int len) throws [MASK] {
stream.write(b, off, len);
bytesWritten += len;
}
@Override
public void flush() throws [MASK] {
stream.flush();
}
@Override
public void close() throws [MASK] {
stream.close();
}
}
| IOException |
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* 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 org.jkiss.dbeaver.tools.transfer.stream.model;
import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPDataSourceInfo;
import org.jkiss.dbeaver.model.data.DBDFormatSettings;
import org.jkiss.dbeaver.model.data.DBDValueHandler;
import org.jkiss.dbeaver.model.data.DBDValueHandlerProvider;
import org.jkiss.dbeaver.model.exec.DBCExecutionContext;
import org.jkiss.dbeaver.model.impl.AbstractSimpleDataSource;
import org.jkiss.dbeaver.model.impl.data.DefaultValueHandler;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLDialect;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSTypedObject;
import java.util.Collection;
/**
* Stream data source. It is a fake client-side datasource to emulate database-like data producers.
*/
public class StreamDataSource extends AbstractSimpleDataSource<StreamExecutionContext> implements DBDValueHandlerProvider {
private final StreamDataSourceDialect dialect;
public StreamDataSource(StreamDataSourceContainer container) {
super(container);
this.executionContext = new StreamExecutionContext(this, "Main");
this.dialect = new StreamDataSourceDialect();
}
public StreamDataSource(String inputName) {
this(new StreamDataSourceContainer(inputName));
}
@NotNull
@ [MASK]
public DBPDataSourceInfo getInfo() {
return new StreamDataSourceInfo();
}
@NotNull
@ [MASK]
public SQLDialect getSQLDialect() {
return dialect;
}
@ [MASK]
public void initialize(@NotNull DBRProgressMonitor monitor) throws DBException {
}
@NotNull
@ [MASK]
public StreamExecutionContext openIsolatedContext(@NotNull DBRProgressMonitor monitor, @NotNull String purpose, @Nullable DBCExecutionContext initFrom) throws DBException {
return new StreamExecutionContext(this, purpose);
}
// We need to implement value handler provider to pass default value handler for attribute bindings
@Nullable
@ [MASK]
public DBDValueHandler getValueHandler(DBPDataSource dataSource, DBDFormatSettings preferences, DBSTypedObject typedObject) {
return DefaultValueHandler.INSTANCE;
}
@ [MASK]
public Collection<? extends DBSObject> getChildren(@NotNull DBRProgressMonitor monitor) throws DBException {
return null;
}
@Nullable
@ [MASK]
public DBSObject getChild(@NotNull DBRProgressMonitor monitor, @NotNull String childName) throws DBException {
return null;
}
@NotNull
@ [MASK]
public Class<? extends DBSObject> getPrimaryChildType(@Nullable DBRProgressMonitor monitor) throws DBException {
return DBSObject.class;
}
@ [MASK]
public void cacheStructure(@NotNull DBRProgressMonitor monitor, int scope) throws DBException {
}
}
| Override |
package com.gateway.web.rest.errors;
import com.gateway.IntegrationTest;
import org.hamcrest.core.AnyOf;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* Integration tests {@link ExceptionTranslator} controller advice.
*/
@WithMockUser
@AutoConfigureWebTestClient(timeout = IntegrationTest.DEFAULT_TIMEOUT)
@IntegrationTest
class ExceptionTranslatorIT {
@Autowired
private WebTestClient webTestClient;
@Test
void testConcurrencyFailure() {
webTestClient
.get()
.uri("/api/exception-translator-test/concurrency-failure")
.exchange()
.expectStatus()
. [MASK] (HttpStatus.CONFLICT)
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
. [MASK] (ErrorConstants.ERR_CONCURRENCY_FAILURE);
}
@Test
void testMethodArgumentNotValid() {
webTestClient
.post()
.uri("/api/exception-translator-test/method-argument")
.contentType(MediaType.APPLICATION_JSON)
.bodyValue("{}")
.exchange()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
. [MASK] (ErrorConstants.ERR_VALIDATION)
.jsonPath("$.fieldErrors.[0].objectName")
. [MASK] ("test")
.jsonPath("$.fieldErrors.[0].field")
. [MASK] ("test")
.jsonPath("$.fieldErrors.[0].message")
. [MASK] ("must not be null");
}
@Test
void testMissingRequestPart() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-part")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
. [MASK] ("error.http.400");
}
@Test
void testMissingRequestParameter() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-parameter")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
. [MASK] ("error.http.400");
}
@Test
void testAccessDenied() {
webTestClient
.get()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isForbidden()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
. [MASK] ("error.http.403")
.jsonPath("$.detail")
. [MASK] ("test access denied!");
}
@Test
void testUnauthorized() {
webTestClient
.get()
.uri("/api/exception-translator-test/unauthorized")
.exchange()
.expectStatus()
.isUnauthorized()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
. [MASK] ("error.http.401")
.jsonPath("$.path")
. [MASK] ("/api/exception-translator-test/unauthorized")
.jsonPath("$.detail")
.value(AnyOf.anyOf(IsEqual.equalTo("test authentication failed!"), IsEqual.equalTo("Invalid credentials")));
}
@Test
void testMethodNotSupported() {
webTestClient
.post()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
. [MASK] (HttpStatus.METHOD_NOT_ALLOWED)
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
. [MASK] ("error.http.405")
.jsonPath("$.detail")
. [MASK] ("405 METHOD_NOT_ALLOWED \"Request method 'POST' is not supported.\"");
}
@Test
void testExceptionWithResponseStatus() {
webTestClient
.get()
.uri("/api/exception-translator-test/response-status")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
. [MASK] ("error.http.400")
.jsonPath("$.title")
. [MASK] ("test response status");
}
@Test
void testInternalServerError() {
webTestClient
.get()
.uri("/api/exception-translator-test/internal-server-error")
.exchange()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
. [MASK] ("error.http.500")
.jsonPath("$.title")
. [MASK] ("Internal Server Error");
}
}
| isEqualTo |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof [MASK] );
(( [MASK] ) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) (( [MASK] ) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| RedissonMapCache |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle [MASK] = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
[MASK] = SharedUtils.adaptDowncallForIMR( [MASK] , cDesc, bindings.callingSequence);
}
return [MASK] ;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Un [MASK] d class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Un [MASK] d class " + argumentClass);
}
return bindings.build();
}
}
}
| handle |
package com.baeldung.kafka.admin;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org. [MASK] .containers.KafkaContainer;
import org. [MASK] .junit.jupiter.Container;
import org. [MASK] .junit.jupiter.Testcontainers;
import org. [MASK] .utility.DockerImageName;
import java.util.Properties;
import static org.assertj.core.api.Assertions.assertThat;
// This live test needs a running Docker instance so that a kafka container can be created
@Testcontainers
class KafkaTopicApplicationLiveTest {
@Container
private static final KafkaContainer KAFKA_CONTAINER = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.4.3"));
private KafkaTopicApplication kafkaTopicApplication;
@BeforeEach
void setup() {
Properties properties = new Properties();
properties.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, KAFKA_CONTAINER.getBootstrapServers());
kafkaTopicApplication = new KafkaTopicApplication(properties);
}
@Test
void givenTopicName_whenCreateNewTopic_thenTopicIsCreated() throws Exception {
kafkaTopicApplication.createTopic("test-topic");
String topicCommand = "/usr/bin/kafka-topics --bootstrap-server=localhost:9092 --list";
String stdout = KAFKA_CONTAINER.execInContainer("/bin/sh", "-c", topicCommand)
.getStdout();
assertThat(stdout).contains("test-topic");
}
}
| testcontainers |
/*
* Copyright (c) 2015, 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.
*
* 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.
*/
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.util.Properties;
/*
* @test
* @bug 8073214 8075362
* @summary Tests to verify that load() and store() throw NPEs as advertised.
*/
public class LoadAndStoreNPE
{
public static void main(String[] args) throws Exception
{
int failures = 0;
Properties props = new Properties();
try {
props.store((OutputStream)null, "comments");
failures++;
} catch ( [MASK] e) {
// do nothing
}
try {
props.store((Writer)null, "comments");
failures++;
} catch ( [MASK] e) {
// do nothing
}
try {
props.load((InputStream)null);
failures++;
} catch ( [MASK] e) {
// do nothing
}
try {
props.load((Reader)null);
failures++;
} catch ( [MASK] e) {
// do nothing
}
if (failures != 0) {
throw new RuntimeException("LoadAndStoreNPE failed with "
+ failures + " errors!");
}
}
}
| NullPointerException |
package cn.iocoder.springcloudalibaba.labx7.dto;
import java.io.Serializable;
/**
* 用户信息 DTO
*/
public class UserDTO implements Serializable {
/**
* 用户编号
*/
private [MASK] id;
/**
* 昵称
*/
private String name;
/**
* 性别
*/
private [MASK] gender;
public [MASK] getId() {
return id;
}
public UserDTO setId( [MASK] id) {
this.id = id;
return this;
}
public String getName() {
return name;
}
public UserDTO setName(String name) {
this.name = name;
return this;
}
public [MASK] getGender() {
return gender;
}
public UserDTO setGender( [MASK] gender) {
this.gender = gender;
return this;
}
}
| Integer |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc. [MASK] ());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc. [MASK] ().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc. [MASK] ().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> [MASK] ) {
return [MASK]
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| returnLayout |
/*
* Copyright (c) 1998, 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.
*
* 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.
*/
/* @test
@bug 4092350
@summary Verify that reads and writes of primitives are correct
*/
// The bug mentioned is actually a performance bug that prompted
// changes in the methods to write primitives
import java.io.*;
import java.io.*;
public class ReadWritePrimitives {
public static void main(String args[]) throws IOException {
long start, finish;
start = System.currentTimeMillis();
testShort();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
start = System.currentTimeMillis();
testChar();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
start = System.currentTimeMillis();
testInt();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
start = System.currentTimeMillis();
testLong();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
}
private static void testShort() throws IOException {
File fh = new File(System. [MASK] ("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeShort((short)i);
}
f.writeShort((short)65535);
f.close();
f = new RandomAccessFile(fh,"r");
for(int i = 0; i < 10000; i++) {
short r = f.readShort();
if (r != ((short)i)) {
System.err.println("An error occurred. Read:" + r
+ " i:" + ((short)i));
throw new IOException("Bad read from a writeShort");
}
}
short rmax = f.readShort();
if (rmax != ((short)65535)) {
System.err.println("An error occurred. Read:" + rmax);
throw new IOException("Bad read from a writeShort");
}
f.close();
}
private static void testChar() throws IOException {
File fh = new File(System. [MASK] ("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeChar((char)i);
}
f.close();
f = new RandomAccessFile(fh,"r");
for(int i = 0; i < 10000; i++) {
char r = f.readChar();
if (r != ((char)i)){
System.err.println("An error occurred. Read:" + r
+ " i:" + ((char) i));
throw new IOException("Bad read from a writeChar");
}
}
f.close();
}
private static void testInt() throws IOException {
File fh = new File(System. [MASK] ("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeInt((short)i);
}
f.writeInt(Integer.MAX_VALUE);
f.close();
f = new RandomAccessFile(fh, "r");
for(int i = 0; i < 10000; i++) {
int r = f.readInt();
if (r != i){
System.err.println("An error occurred. Read:" + r
+ " i:" + i);
throw new IOException("Bad read from a writeInt");
}
}
int rmax = f.readInt();
if (rmax != Integer.MAX_VALUE){
System.err.println("An error occurred. Read:" + rmax);
throw new IOException("Bad read from a writeInt");
}
f.close();
}
private static void testLong() throws IOException {
File fh = new File(System. [MASK] ("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeLong(123456789L * (long)i);
}
f.close();
f = new RandomAccessFile(fh,"r");
for(int i = 0; i < 10000; i++){
long r = f.readLong();
if (r != (((long) i) * 123456789L) ) {
System.err.println("An error occurred. Read:" + r
+ " i" + ((long) i));
throw new IOException("Bad read from a writeInt");
}
}
f.close();
}
}
| getProperty |
/*
* Copyright 1999-2017 Alibaba Group Holding Ltd.
*
* 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.alibaba. [MASK] .sql.dialect.oracle.ast;
import com.alibaba. [MASK] .sql.ast.SQLName;
import com.alibaba. [MASK] .sql.ast.SQLObject;
/**
* Created by wenshao on 21/05/2017.
*/
public interface OracleSegmentAttributes extends SQLObject {
SQLName getTablespace();
void setTablespace(SQLName name);
Boolean getCompress();
void setCompress(Boolean compress);
Integer getCompressLevel();
void setCompressLevel(Integer compressLevel);
Integer getInitrans();
void setInitrans(Integer initrans);
Integer getMaxtrans();
void setMaxtrans(Integer maxtrans);
Integer getPctincrease();
void setPctincrease(Integer pctincrease);
Integer getPctused();
void setPctused(Integer pctused);
Integer getPctfree();
void setPctfree(Integer ptcfree);
Boolean getLogging();
void setLogging(Boolean logging);
SQLObject getStorage();
void setStorage(SQLObject storage);
boolean isCompressForOltp();
void setCompressForOltp(boolean compressForOltp);
}
| druid |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
[MASK] <Object> b1 = batch.getBucket("b1");
[MASK] <Object> b2 = batch.getBucket("b2");
[MASK] <Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
[MASK] <Object> b1 = batch.getBucket("b1");
[MASK] <Object> b2 = batch.getBucket("b2");
[MASK] <Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| RBucketAsync |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign. [MASK] ;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.Shared [MASK] ;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =Shared [MASK] .C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = Shared [MASK] .adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return Shared [MASK] .arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = [MASK] .alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = Shared [MASK] .primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = Shared [MASK] .primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = Shared [MASK] .primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = Shared [MASK] .primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw( [MASK] .pointeeByteSize(addressLayout), [MASK] .pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| Utils |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int [MASK] = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + [MASK] ) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += [MASK] ;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| gpRegCnt |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean [MASK] ) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if ( [MASK] ) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if ( [MASK] ) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| is32Bit |
package com.gateway.web.rest.errors;
import com.gateway.IntegrationTest;
import org.hamcrest.core.AnyOf;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.http. [MASK] ;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* Integration tests {@link ExceptionTranslator} controller advice.
*/
@WithMockUser
@AutoConfigureWebTestClient(timeout = IntegrationTest.DEFAULT_TIMEOUT)
@IntegrationTest
class ExceptionTranslatorIT {
@Autowired
private WebTestClient webTestClient;
@Test
void testConcurrencyFailure() {
webTestClient
.get()
.uri("/api/exception-translator-test/concurrency-failure")
.exchange()
.expectStatus()
.isEqualTo( [MASK] .CONFLICT)
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo(ErrorConstants.ERR_CONCURRENCY_FAILURE);
}
@Test
void testMethodArgumentNotValid() {
webTestClient
.post()
.uri("/api/exception-translator-test/method-argument")
.contentType(MediaType.APPLICATION_JSON)
.bodyValue("{}")
.exchange()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo(ErrorConstants.ERR_VALIDATION)
.jsonPath("$.fieldErrors.[0].objectName")
.isEqualTo("test")
.jsonPath("$.fieldErrors.[0].field")
.isEqualTo("test")
.jsonPath("$.fieldErrors.[0].message")
.isEqualTo("must not be null");
}
@Test
void testMissingRequestPart() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-part")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400");
}
@Test
void testMissingRequestParameter() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-parameter")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400");
}
@Test
void testAccessDenied() {
webTestClient
.get()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isForbidden()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.403")
.jsonPath("$.detail")
.isEqualTo("test access denied!");
}
@Test
void testUnauthorized() {
webTestClient
.get()
.uri("/api/exception-translator-test/unauthorized")
.exchange()
.expectStatus()
.isUnauthorized()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.401")
.jsonPath("$.path")
.isEqualTo("/api/exception-translator-test/unauthorized")
.jsonPath("$.detail")
.value(AnyOf.anyOf(IsEqual.equalTo("test authentication failed!"), IsEqual.equalTo("Invalid credentials")));
}
@Test
void testMethodNotSupported() {
webTestClient
.post()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isEqualTo( [MASK] .METHOD_NOT_ALLOWED)
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.405")
.jsonPath("$.detail")
.isEqualTo("405 METHOD_NOT_ALLOWED \"Request method 'POST' is not supported.\"");
}
@Test
void testExceptionWithResponseStatus() {
webTestClient
.get()
.uri("/api/exception-translator-test/response-status")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400")
.jsonPath("$.title")
.isEqualTo("test response status");
}
@Test
void testInternalServerError() {
webTestClient
.get()
.uri("/api/exception-translator-test/internal-server-error")
.exchange()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.500")
.jsonPath("$.title")
.isEqualTo("Internal Server Error");
}
}
| HttpStatus |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
[MASK] .TestREntity rlo = new [MASK] .TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", (( [MASK] .TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", (( [MASK] .TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| RedissonLiveObjectServiceTest |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new [MASK] (true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new [MASK] (false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class [MASK] extends BindingCalculator {
private final boolean useAddressPairs;
[MASK] (boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| UnboxBindingCalculator |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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. [MASK] .abi.s390.linux;
import jdk.internal. [MASK] .Utils;
import jdk.internal. [MASK] .abi.ABIDescriptor;
import jdk.internal. [MASK] .abi.AbstractLinker.UpcallStubFactory;
import jdk.internal. [MASK] .abi.Binding;
import jdk.internal. [MASK] .abi.CallingSequence;
import jdk.internal. [MASK] .abi.CallingSequenceBuilder;
import jdk.internal. [MASK] .abi.DowncallLinker;
import jdk.internal. [MASK] .abi.LinkerOptions;
import jdk.internal. [MASK] .abi.SharedUtils;
import jdk.internal. [MASK] .abi.VMStorage;
import java.lang. [MASK] .AddressLayout;
import java.lang. [MASK] .FunctionDescriptor;
import java.lang. [MASK] .GroupLayout;
import java.lang. [MASK] .MemoryLayout;
import java.lang. [MASK] .MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal. [MASK] .abi.s390.S390Architecture.*;
import static jdk.internal. [MASK] .abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| foreign |
/**
* Copyright (c) 2013-2024 Nikita Koksharov
*
* 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 org.redisson.hibernate.strategy;
import org.hibernate.cache. [MASK] ;
import org.hibernate.cache.internal.DefaultCacheKeysFactory;
import org.hibernate.cache.spi.EntityRegion;
import org.hibernate.cache.spi.GeneralDataRegion;
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
import org.hibernate.cache.spi.access.SoftLock;
import org.hibernate.cfg.Settings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.redisson.hibernate.region.RedissonEntityRegion;
/**
*
* @author Nikita Koksharov
*
*/
public class ReadOnlyEntityRegionAccessStrategy extends BaseRegionAccessStrategy implements EntityRegionAccessStrategy {
public ReadOnlyEntityRegionAccessStrategy(Settings settings, GeneralDataRegion region) {
super(settings, region);
}
@Override
public Object get(SessionImplementor session, Object key, long txTimestamp) throws [MASK] {
return region.get(session, key);
}
@Override
public boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws [MASK] {
if (minimalPutOverride && region.contains(key)) {
return false;
}
region.put(session, key, value);
return true;
}
@Override
public SoftLock lockItem(SessionImplementor session, Object key, Object version) throws [MASK] {
return null;
}
@Override
public void unlockItem(SessionImplementor session, Object key, SoftLock lock) throws [MASK] {
evict(key);
}
@Override
public EntityRegion getRegion() {
return (EntityRegion) region;
}
@Override
public boolean insert(SessionImplementor session, Object key, Object value, Object version) throws [MASK] {
return false;
}
@Override
public boolean afterInsert(SessionImplementor session, Object key, Object value, Object version) throws [MASK] {
region.put(session, key, value);
return true;
}
@Override
public boolean update(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion)
throws [MASK] {
throw new UnsupportedOperationException("Unable to update read-only object");
}
@Override
public boolean afterUpdate(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
throws [MASK] {
throw new UnsupportedOperationException("Unable to update read-only object");
}
@Override
public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) {
return ((RedissonEntityRegion)region).getCacheKeysFactory().createEntityKey( id, persister, factory, tenantIdentifier );
}
@Override
public Object getCacheKeyId(Object cacheKey) {
return ((RedissonEntityRegion)region).getCacheKeysFactory().getEntityId(cacheKey);
}
}
| CacheException |
package com.baeldung.kafka.admin;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import java.util.Properties;
import static org.assertj.core.api.Assertions.assertThat;
// This live test needs a running Docker instance so that a kafka container can be created
@Testcontainers
class KafkaTopicApplicationLiveTest {
@Container
private static final KafkaContainer KAFKA_CONTAINER = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.4.3"));
private KafkaTopicApplication [MASK] ;
@BeforeEach
void setup() {
Properties properties = new Properties();
properties.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, KAFKA_CONTAINER.getBootstrapServers());
[MASK] = new KafkaTopicApplication(properties);
}
@Test
void givenTopicName_whenCreateNewTopic_thenTopicIsCreated() throws Exception {
[MASK] .createTopic("test-topic");
String topicCommand = "/usr/bin/kafka-topics --bootstrap-server=localhost:9092 --list";
String stdout = KAFKA_CONTAINER.execInContainer("/bin/sh", "-c", topicCommand)
.getStdout();
assertThat(stdout).contains("test-topic");
}
}
| kafkaTopicApplication |
/**
* Copyright (c) 2013-2024 Nikita Koksharov
*
* 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 org.redisson.hibernate.strategy;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.internal.DefaultCacheKeysFactory;
import org.hibernate.cache.spi.EntityRegion;
import org.hibernate.cache.spi.GeneralDataRegion;
import org.hibernate.cache.spi.access.EntityRegionAccessStrategy;
import org.hibernate.cache.spi.access.SoftLock;
import org.hibernate.cfg.Settings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.redisson.hibernate. [MASK] .RedissonEntityRegion;
/**
*
* @author Nikita Koksharov
*
*/
public class ReadOnlyEntityRegionAccessStrategy extends BaseRegionAccessStrategy implements EntityRegionAccessStrategy {
public ReadOnlyEntityRegionAccessStrategy(Settings settings, GeneralDataRegion [MASK] ) {
super(settings, [MASK] );
}
@Override
public Object get(SessionImplementor session, Object key, long txTimestamp) throws CacheException {
return [MASK] .get(session, key);
}
@Override
public boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException {
if (minimalPutOverride && [MASK] .contains(key)) {
return false;
}
[MASK] .put(session, key, value);
return true;
}
@Override
public SoftLock lockItem(SessionImplementor session, Object key, Object version) throws CacheException {
return null;
}
@Override
public void unlockItem(SessionImplementor session, Object key, SoftLock lock) throws CacheException {
evict(key);
}
@Override
public EntityRegion getRegion() {
return (EntityRegion) [MASK] ;
}
@Override
public boolean insert(SessionImplementor session, Object key, Object value, Object version) throws CacheException {
return false;
}
@Override
public boolean afterInsert(SessionImplementor session, Object key, Object value, Object version) throws CacheException {
[MASK] .put(session, key, value);
return true;
}
@Override
public boolean update(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion)
throws CacheException {
throw new UnsupportedOperationException("Unable to update read-only object");
}
@Override
public boolean afterUpdate(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
throws CacheException {
throw new UnsupportedOperationException("Unable to update read-only object");
}
@Override
public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) {
return ((RedissonEntityRegion) [MASK] ).getCacheKeysFactory().createEntityKey( id, persister, factory, tenantIdentifier );
}
@Override
public Object getCacheKeyId(Object cacheKey) {
return ((RedissonEntityRegion) [MASK] ).getCacheKeysFactory().getEntityId(cacheKey);
}
}
| region |
/*
* Copyright (c) 1998, 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.
*
* 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.
*/
/* @test
@bug 4092350
@summary Verify that reads and writes of primitives are correct
*/
// The bug mentioned is actually a performance bug that prompted
// changes in the methods to write primitives
import java.io.*;
import java.io.*;
public class ReadWritePrimitives {
public static void main(String args[]) throws IOException {
long start, finish;
start = System.currentTimeMillis();
testShort();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
start = System.currentTimeMillis();
testChar();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
start = System.currentTimeMillis();
testInt();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
start = System.currentTimeMillis();
testLong();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
}
private static void testShort() throws IOException {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
[MASK] f = new [MASK] (fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeShort((short)i);
}
f.writeShort((short)65535);
f.close();
f = new [MASK] (fh,"r");
for(int i = 0; i < 10000; i++) {
short r = f.readShort();
if (r != ((short)i)) {
System.err.println("An error occurred. Read:" + r
+ " i:" + ((short)i));
throw new IOException("Bad read from a writeShort");
}
}
short rmax = f.readShort();
if (rmax != ((short)65535)) {
System.err.println("An error occurred. Read:" + rmax);
throw new IOException("Bad read from a writeShort");
}
f.close();
}
private static void testChar() throws IOException {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
[MASK] f = new [MASK] (fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeChar((char)i);
}
f.close();
f = new [MASK] (fh,"r");
for(int i = 0; i < 10000; i++) {
char r = f.readChar();
if (r != ((char)i)){
System.err.println("An error occurred. Read:" + r
+ " i:" + ((char) i));
throw new IOException("Bad read from a writeChar");
}
}
f.close();
}
private static void testInt() throws IOException {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
[MASK] f = new [MASK] (fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeInt((short)i);
}
f.writeInt(Integer.MAX_VALUE);
f.close();
f = new [MASK] (fh, "r");
for(int i = 0; i < 10000; i++) {
int r = f.readInt();
if (r != i){
System.err.println("An error occurred. Read:" + r
+ " i:" + i);
throw new IOException("Bad read from a writeInt");
}
}
int rmax = f.readInt();
if (rmax != Integer.MAX_VALUE){
System.err.println("An error occurred. Read:" + rmax);
throw new IOException("Bad read from a writeInt");
}
f.close();
}
private static void testLong() throws IOException {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
[MASK] f = new [MASK] (fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeLong(123456789L * (long)i);
}
f.close();
f = new [MASK] (fh,"r");
for(int i = 0; i < 10000; i++){
long r = f.readLong();
if (r != (((long) i) * 123456789L) ) {
System.err.println("An error occurred. Read:" + r
+ " i" + ((long) i));
throw new IOException("Bad read from a writeInt");
}
}
f.close();
}
}
| RandomAccessFile |
package emu. [MASK] .server.packet.send;
import emu. [MASK] .game.friends.Friendship;
import emu. [MASK] .game.player.Player;
import emu. [MASK] .net.packet.*;
import emu. [MASK] .net.proto.GetPlayerAskFriendListRspOuterClass.GetPlayerAskFriendListRsp;
public class PacketGetPlayerAskFriendListRsp extends BasePacket {
public PacketGetPlayerAskFriendListRsp(Player player) {
super(PacketOpcodes.GetPlayerAskFriendListRsp);
GetPlayerAskFriendListRsp.Builder proto = GetPlayerAskFriendListRsp.newBuilder();
for (Friendship friendship : player.getFriendsList().getPendingFriends().values()) {
if (friendship.getAskerId() == player.getUid()) {
continue;
}
proto.addAskFriendList(friendship.toProto());
}
this.setData(proto);
}
}
| grasscutter |
package com.gateway.web.rest.errors;
import com.gateway.IntegrationTest;
import org.hamcrest.core.AnyOf;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* Integration tests {@link ExceptionTranslator} controller advice.
*/
@WithMockUser
@AutoConfigureWebTestClient(timeout = IntegrationTest.DEFAULT_TIMEOUT)
@IntegrationTest
class ExceptionTranslatorIT {
@Autowired
private WebTestClient webTestClient;
@Test
void testConcurrencyFailure() {
webTestClient
.get()
.uri("/api/exception-translator-test/concurrency-failure")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.CONFLICT)
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
. [MASK] ("$.message")
.isEqualTo(ErrorConstants.ERR_CONCURRENCY_FAILURE);
}
@Test
void testMethodArgumentNotValid() {
webTestClient
.post()
.uri("/api/exception-translator-test/method-argument")
.contentType(MediaType.APPLICATION_JSON)
.bodyValue("{}")
.exchange()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
. [MASK] ("$.message")
.isEqualTo(ErrorConstants.ERR_VALIDATION)
. [MASK] ("$.fieldErrors.[0].objectName")
.isEqualTo("test")
. [MASK] ("$.fieldErrors.[0].field")
.isEqualTo("test")
. [MASK] ("$.fieldErrors.[0].message")
.isEqualTo("must not be null");
}
@Test
void testMissingRequestPart() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-part")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
. [MASK] ("$.message")
.isEqualTo("error.http.400");
}
@Test
void testMissingRequestParameter() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-parameter")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
. [MASK] ("$.message")
.isEqualTo("error.http.400");
}
@Test
void testAccessDenied() {
webTestClient
.get()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isForbidden()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
. [MASK] ("$.message")
.isEqualTo("error.http.403")
. [MASK] ("$.detail")
.isEqualTo("test access denied!");
}
@Test
void testUnauthorized() {
webTestClient
.get()
.uri("/api/exception-translator-test/unauthorized")
.exchange()
.expectStatus()
.isUnauthorized()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
. [MASK] ("$.message")
.isEqualTo("error.http.401")
. [MASK] ("$.path")
.isEqualTo("/api/exception-translator-test/unauthorized")
. [MASK] ("$.detail")
.value(AnyOf.anyOf(IsEqual.equalTo("test authentication failed!"), IsEqual.equalTo("Invalid credentials")));
}
@Test
void testMethodNotSupported() {
webTestClient
.post()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.METHOD_NOT_ALLOWED)
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
. [MASK] ("$.message")
.isEqualTo("error.http.405")
. [MASK] ("$.detail")
.isEqualTo("405 METHOD_NOT_ALLOWED \"Request method 'POST' is not supported.\"");
}
@Test
void testExceptionWithResponseStatus() {
webTestClient
.get()
.uri("/api/exception-translator-test/response-status")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
. [MASK] ("$.message")
.isEqualTo("error.http.400")
. [MASK] ("$.title")
.isEqualTo("test response status");
}
@Test
void testInternalServerError() {
webTestClient
.get()
.uri("/api/exception-translator-test/internal-server-error")
.exchange()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
. [MASK] ("$.message")
.isEqualTo("error.http.500")
. [MASK] ("$.title")
.isEqualTo("Internal Server Error");
}
}
| jsonPath |
package com.gateway.web.rest.errors;
import com.gateway.IntegrationTest;
import org.hamcrest.core.AnyOf;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* Integration tests {@link ExceptionTranslator} controller advice.
*/
@WithMockUser
@AutoConfigureWebTestClient(timeout = IntegrationTest.DEFAULT_TIMEOUT)
@IntegrationTest
class ExceptionTranslatorIT {
@Autowired
private WebTestClient [MASK] ;
@Test
void testConcurrencyFailure() {
[MASK]
.get()
.uri("/api/exception-translator-test/concurrency-failure")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.CONFLICT)
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo(ErrorConstants.ERR_CONCURRENCY_FAILURE);
}
@Test
void testMethodArgumentNotValid() {
[MASK]
.post()
.uri("/api/exception-translator-test/method-argument")
.contentType(MediaType.APPLICATION_JSON)
.bodyValue("{}")
.exchange()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo(ErrorConstants.ERR_VALIDATION)
.jsonPath("$.fieldErrors.[0].objectName")
.isEqualTo("test")
.jsonPath("$.fieldErrors.[0].field")
.isEqualTo("test")
.jsonPath("$.fieldErrors.[0].message")
.isEqualTo("must not be null");
}
@Test
void testMissingRequestPart() {
[MASK]
.get()
.uri("/api/exception-translator-test/missing-servlet-request-part")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400");
}
@Test
void testMissingRequestParameter() {
[MASK]
.get()
.uri("/api/exception-translator-test/missing-servlet-request-parameter")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400");
}
@Test
void testAccessDenied() {
[MASK]
.get()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isForbidden()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.403")
.jsonPath("$.detail")
.isEqualTo("test access denied!");
}
@Test
void testUnauthorized() {
[MASK]
.get()
.uri("/api/exception-translator-test/unauthorized")
.exchange()
.expectStatus()
.isUnauthorized()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.401")
.jsonPath("$.path")
.isEqualTo("/api/exception-translator-test/unauthorized")
.jsonPath("$.detail")
.value(AnyOf.anyOf(IsEqual.equalTo("test authentication failed!"), IsEqual.equalTo("Invalid credentials")));
}
@Test
void testMethodNotSupported() {
[MASK]
.post()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.METHOD_NOT_ALLOWED)
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.405")
.jsonPath("$.detail")
.isEqualTo("405 METHOD_NOT_ALLOWED \"Request method 'POST' is not supported.\"");
}
@Test
void testExceptionWithResponseStatus() {
[MASK]
.get()
.uri("/api/exception-translator-test/response-status")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400")
.jsonPath("$.title")
.isEqualTo("test response status");
}
@Test
void testInternalServerError() {
[MASK]
.get()
.uri("/api/exception-translator-test/internal-server-error")
.exchange()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.500")
.jsonPath("$.title")
.isEqualTo("Internal Server Error");
}
}
| webTestClient |
package cn.iocoder.springcloudalibaba.labx7.dto;
import java.io.Serializable;
/**
* 用户信息 DTO
*/
public class [MASK] implements Serializable {
/**
* 用户编号
*/
private Integer id;
/**
* 昵称
*/
private String name;
/**
* 性别
*/
private Integer gender;
public Integer getId() {
return id;
}
public [MASK] setId(Integer id) {
this.id = id;
return this;
}
public String getName() {
return name;
}
public [MASK] setName(String name) {
this.name = name;
return this;
}
public Integer getGender() {
return gender;
}
public [MASK] setGender(Integer gender) {
this.gender = gender;
return this;
}
}
| UserDTO |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator [MASK] = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, [MASK] .getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, [MASK] .getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| argCalc |
package com.gateway.web.rest.errors;
import com.gateway.IntegrationTest;
import org.hamcrest.core.AnyOf;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* Integration tests {@link ExceptionTranslator} controller advice.
*/
@WithMockUser
@AutoConfigureWebTestClient(timeout = IntegrationTest.DEFAULT_TIMEOUT)
@IntegrationTest
class ExceptionTranslatorIT {
@Autowired
private WebTestClient webTestClient;
@Test
void testConcurrencyFailure() {
webTestClient
.get()
.uri("/api/exception-translator-test/concurrency-failure")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.CONFLICT)
.expectHeader()
.contentType(MediaType. [MASK] )
.expectBody()
.jsonPath("$.message")
.isEqualTo(ErrorConstants.ERR_CONCURRENCY_FAILURE);
}
@Test
void testMethodArgumentNotValid() {
webTestClient
.post()
.uri("/api/exception-translator-test/method-argument")
.contentType(MediaType.APPLICATION_JSON)
.bodyValue("{}")
.exchange()
.expectHeader()
.contentType(MediaType. [MASK] )
.expectBody()
.jsonPath("$.message")
.isEqualTo(ErrorConstants.ERR_VALIDATION)
.jsonPath("$.fieldErrors.[0].objectName")
.isEqualTo("test")
.jsonPath("$.fieldErrors.[0].field")
.isEqualTo("test")
.jsonPath("$.fieldErrors.[0].message")
.isEqualTo("must not be null");
}
@Test
void testMissingRequestPart() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-part")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType. [MASK] )
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400");
}
@Test
void testMissingRequestParameter() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-parameter")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType. [MASK] )
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400");
}
@Test
void testAccessDenied() {
webTestClient
.get()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isForbidden()
.expectHeader()
.contentType(MediaType. [MASK] )
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.403")
.jsonPath("$.detail")
.isEqualTo("test access denied!");
}
@Test
void testUnauthorized() {
webTestClient
.get()
.uri("/api/exception-translator-test/unauthorized")
.exchange()
.expectStatus()
.isUnauthorized()
.expectHeader()
.contentType(MediaType. [MASK] )
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.401")
.jsonPath("$.path")
.isEqualTo("/api/exception-translator-test/unauthorized")
.jsonPath("$.detail")
.value(AnyOf.anyOf(IsEqual.equalTo("test authentication failed!"), IsEqual.equalTo("Invalid credentials")));
}
@Test
void testMethodNotSupported() {
webTestClient
.post()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.METHOD_NOT_ALLOWED)
.expectHeader()
.contentType(MediaType. [MASK] )
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.405")
.jsonPath("$.detail")
.isEqualTo("405 METHOD_NOT_ALLOWED \"Request method 'POST' is not supported.\"");
}
@Test
void testExceptionWithResponseStatus() {
webTestClient
.get()
.uri("/api/exception-translator-test/response-status")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType. [MASK] )
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400")
.jsonPath("$.title")
.isEqualTo("test response status");
}
@Test
void testInternalServerError() {
webTestClient
.get()
.uri("/api/exception-translator-test/internal-server-error")
.exchange()
.expectHeader()
.contentType(MediaType. [MASK] )
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.500")
.jsonPath("$.title")
.isEqualTo("Internal Server Error");
}
}
| APPLICATION_PROBLEM_JSON |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient [MASK] = Redisson.create(config);
RBucket<Object> b1 = [MASK] .getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = [MASK] .getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient [MASK] 1 = Redisson.create(config);
RSet<RBucket> s2 = [MASK] 1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
[MASK] .shutdown();
[MASK] 1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| redissonClient |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions [MASK] ) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, [MASK] );
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, [MASK] .allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions [MASK] ) {
Bindings bindings = getBindings(mt, cDesc, false, [MASK] );
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions [MASK] ) {
Bindings bindings = getBindings(mt, cDesc, true, [MASK] );
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| options |
/*
* Copyright (c) 1998, 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.
*
* 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.
*/
/* @test
@bug 4092350
@summary Verify that reads and writes of primitives are correct
*/
// The bug mentioned is actually a performance bug that prompted
// changes in the methods to write primitives
import java.io.*;
import java.io.*;
public class ReadWritePrimitives {
public static void main(String args[]) throws IOException {
long [MASK] , finish;
[MASK] = System.currentTimeMillis();
testShort();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish- [MASK] ));
[MASK] = System.currentTimeMillis();
testChar();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish- [MASK] ));
[MASK] = System.currentTimeMillis();
testInt();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish- [MASK] ));
[MASK] = System.currentTimeMillis();
testLong();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish- [MASK] ));
}
private static void testShort() throws IOException {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeShort((short)i);
}
f.writeShort((short)65535);
f.close();
f = new RandomAccessFile(fh,"r");
for(int i = 0; i < 10000; i++) {
short r = f.readShort();
if (r != ((short)i)) {
System.err.println("An error occurred. Read:" + r
+ " i:" + ((short)i));
throw new IOException("Bad read from a writeShort");
}
}
short rmax = f.readShort();
if (rmax != ((short)65535)) {
System.err.println("An error occurred. Read:" + rmax);
throw new IOException("Bad read from a writeShort");
}
f.close();
}
private static void testChar() throws IOException {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeChar((char)i);
}
f.close();
f = new RandomAccessFile(fh,"r");
for(int i = 0; i < 10000; i++) {
char r = f.readChar();
if (r != ((char)i)){
System.err.println("An error occurred. Read:" + r
+ " i:" + ((char) i));
throw new IOException("Bad read from a writeChar");
}
}
f.close();
}
private static void testInt() throws IOException {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeInt((short)i);
}
f.writeInt(Integer.MAX_VALUE);
f.close();
f = new RandomAccessFile(fh, "r");
for(int i = 0; i < 10000; i++) {
int r = f.readInt();
if (r != i){
System.err.println("An error occurred. Read:" + r
+ " i:" + i);
throw new IOException("Bad read from a writeInt");
}
}
int rmax = f.readInt();
if (rmax != Integer.MAX_VALUE){
System.err.println("An error occurred. Read:" + rmax);
throw new IOException("Bad read from a writeInt");
}
f.close();
}
private static void testLong() throws IOException {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeLong(123456789L * (long)i);
}
f.close();
f = new RandomAccessFile(fh,"r");
for(int i = 0; i < 10000; i++){
long r = f.readLong();
if (r != (((long) i) * 123456789L) ) {
System.err.println("An error occurred. Read:" + r
+ " i" + ((long) i));
throw new IOException("Bad read from a writeInt");
}
}
f.close();
}
}
| start |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions. [MASK] ());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions. [MASK] ());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions. [MASK] ());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions. [MASK] ());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| defaults |
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* 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 org.jkiss.dbeaver.tools.transfer.stream;
import org.jkiss.code.NotNull;
import java.io.IOException;
import java.io.OutputStream;
public class StatOutputStream extends OutputStream {
private final OutputStream stream;
private long bytesWritten = 0;
public StatOutputStream(OutputStream stream) {
this.stream = stream;
}
public long getBytesWritten() {
return bytesWritten;
}
@ [MASK]
public void write(int b) throws IOException {
stream.write(b);
bytesWritten++;
}
@ [MASK]
public void write(@NotNull byte[] b) throws IOException {
stream.write(b);
bytesWritten += b.length;
}
@ [MASK]
public void write(@NotNull byte[] b, int off, int len) throws IOException {
stream.write(b, off, len);
bytesWritten += len;
}
@ [MASK]
public void flush() throws IOException {
stream.flush();
}
@ [MASK]
public void close() throws IOException {
stream.close();
}
}
| Override |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config. [MASK] ;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
[MASK] config = new [MASK] ();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.get [MASK] ().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| Config |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_ [MASK] _REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType. [MASK] ) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType. [MASK] && (nRegs[StorageType. [MASK] ] + fpRegCnt) > MAX_ [MASK] _REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType. [MASK] ] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType. [MASK] , layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case [MASK] -> {
VMStorage storage = storageCalculator.getStorage(StorageType. [MASK] , carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType. [MASK] , layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case [MASK] -> {
VMStorage storage = storageCalculator.getStorage(StorageType. [MASK] , carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| FLOAT |
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.friends.Friendship;
import emu.grasscutter.game. [MASK] .Player;
import emu.grasscutter.net.packet.*;
import emu.grasscutter.net.proto.GetPlayerAskFriendListRspOuterClass.GetPlayerAskFriendListRsp;
public class PacketGetPlayerAskFriendListRsp extends BasePacket {
public PacketGetPlayerAskFriendListRsp(Player [MASK] ) {
super(PacketOpcodes.GetPlayerAskFriendListRsp);
GetPlayerAskFriendListRsp.Builder proto = GetPlayerAskFriendListRsp.newBuilder();
for (Friendship friendship : [MASK] .getFriendsList().getPendingFriends().values()) {
if (friendship.getAskerId() == [MASK] .getUid()) {
continue;
}
proto.addAskFriendList(friendship.toProto());
}
this.setData(proto);
}
}
| player |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings. [MASK] (storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings. [MASK] (storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings. [MASK] (storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings. [MASK] (storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings. [MASK] (storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings. [MASK] (storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| vmLoad |
package cn.iocoder.springcloudalibaba.labx7.dto;
import java.io.Serializable;
/**
* 用户信息 DTO
*/
public class UserDTO implements Serializable {
/**
* 用户编号
*/
private Integer id;
/**
* 昵称
*/
private String name;
/**
* 性别
*/
private Integer [MASK] ;
public Integer getId() {
return id;
}
public UserDTO setId(Integer id) {
this.id = id;
return this;
}
public String getName() {
return name;
}
public UserDTO setName(String name) {
this.name = name;
return this;
}
public Integer getGender() {
return [MASK] ;
}
public UserDTO setGender(Integer [MASK] ) {
this. [MASK] = [MASK] ;
return this;
}
}
| gender |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit. [MASK] );
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit. [MASK] );
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4.readAllKeySet().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit. [MASK] );
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2.readAllKeySet().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4.readAllKeySet().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| MINUTES |
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2024 DBeaver Corp and others
*
* 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 org.jkiss.dbeaver.tools.transfer. [MASK] ;
import org.jkiss.code.NotNull;
import java.io.IOException;
import java.io.OutputStream;
public class StatOutputStream extends OutputStream {
private final OutputStream [MASK] ;
private long bytesWritten = 0;
public StatOutputStream(OutputStream [MASK] ) {
this. [MASK] = [MASK] ;
}
public long getBytesWritten() {
return bytesWritten;
}
@Override
public void write(int b) throws IOException {
[MASK] .write(b);
bytesWritten++;
}
@Override
public void write(@NotNull byte[] b) throws IOException {
[MASK] .write(b);
bytesWritten += b.length;
}
@Override
public void write(@NotNull byte[] b, int off, int len) throws IOException {
[MASK] .write(b, off, len);
bytesWritten += len;
}
@Override
public void flush() throws IOException {
[MASK] .flush();
}
@Override
public void close() throws IOException {
[MASK] .close();
}
}
| stream |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout [MASK] = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize( [MASK] ), Utils.pointeeByteAlign( [MASK] ));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| addressLayout |
package emu.grasscutter.server.packet.send;
import emu.grasscutter.game.friends.Friendship;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.net.packet.*;
import emu.grasscutter.net. [MASK] .GetPlayerAskFriendListRspOuterClass.GetPlayerAskFriendListRsp;
public class PacketGetPlayerAskFriendListRsp extends BasePacket {
public PacketGetPlayerAskFriendListRsp(Player player) {
super(PacketOpcodes.GetPlayerAskFriendListRsp);
GetPlayerAskFriendListRsp.Builder [MASK] = GetPlayerAskFriendListRsp.newBuilder();
for (Friendship friendship : player.getFriendsList().getPendingFriends().values()) {
if (friendship.getAskerId() == player.getUid()) {
continue;
}
[MASK] .addAskFriendList(friendship.toProto());
}
this.setData( [MASK] );
}
}
| proto |
package org.redisson;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redisson.api.*;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.ScoredEntry;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.Kryo5Codec;
import org.redisson.config.Config;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class RedissonReferenceTest extends RedisDockerTest {
@Test
public void testBitSet() {
RMap<String, RBitSet> data = redisson.getMap("data-00");
RBitSet bs = redisson.getBitSet("data-01");
bs.set(5);
bs.set(7);
data.put("a", bs);
assertThat(data.entrySet()).hasSize(1);
for (Map.Entry<String, RBitSet> entry : data.entrySet()) {
assertThat(entry.getValue().get(5)).isTrue();
assertThat(entry.getValue().get(7)).isTrue();
}
}
@Test
public void testBasic() {
RBucket<Object> b1 = redisson.getBucket("b1");
RBucket<Object> b2 = redisson.getBucket("b2");
RBucket<Object> b3 = redisson.getBucket("b3");
b2.set(b3);
b1.set(redisson.getBucket("b2"));
Assertions.assertTrue(b1.get().getClass().equals(RedissonBucket.class));
Assertions.assertEquals("b3", ((RBucket) ((RBucket) b1.get()).get()).getName());
RBucket<Object> b4 = redisson.getBucket("b4");
b4.set(redisson.getMapCache("testCache"));
Assertions.assertTrue(b4.get() instanceof RedissonMapCache);
((RedissonMapCache) b4.get()).fastPut(b1, b2, 1, TimeUnit.MINUTES);
Assertions.assertEquals("b2", ((RBucket) ((RedissonMapCache) b4.get()).get(b1)).getName());
RBucket<Object> b5 = redisson.getBucket("b5");
RLiveObjectService service = redisson.getLiveObjectService();
RedissonLiveObjectServiceTest.TestREntity rlo = new RedissonLiveObjectServiceTest.TestREntity("123");
rlo = service.persist(rlo);
rlo.setName("t1");
rlo.setValue("t2");
b5.set(rlo);
Assertions.assertTrue(redisson.getBucket("b5").get() instanceof RLiveObject);
Assertions.assertEquals("t1", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getName());
Assertions.assertEquals("t2", ((RedissonLiveObjectServiceTest.TestREntity) redisson.getBucket("b5").get()).getValue());
}
@Test
public void testBatch() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
batch = redisson.createBatch();
batch.getBucket("b1").getAsync();
batch.getBucket("b2").getAsync();
batch.getBucket("b3").getAsync();
List<RBucket> result = (List<RBucket>) batch.execute().getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testNormalToReactive() {
RBatch batch = redisson.createBatch();
RBucketAsync<Object> b1 = batch.getBucket("b1");
RBucketAsync<Object> b2 = batch.getBucket("b2");
RBucketAsync<Object> b3 = batch.getBucket("b3");
b2.setAsync(b3);
b1.setAsync(b2);
b3.setAsync(b1);
batch.execute();
RBatchReactive b = redisson.reactive().createBatch();
b.getBucket("b1").get();
b.getBucket("b2").get();
b.getBucket("b3").get();
List<RBucketReactive> result = (List<RBucketReactive>) BaseReactiveTest.sync(b.execute()).getResponses();
Assertions.assertEquals("b2", result.get(0).getName());
Assertions.assertEquals("b3", result.get(1).getName());
Assertions.assertEquals("b1", result.get(2).getName());
}
@Test
public void testWithList() {
RSet<RBucket<String>> b1 = redisson.getSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
}
@Test
public void testWithZSet() {
RScoredSortedSet<RBucket<String>> b1 = redisson.getScoredSortedSet("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(0.0, b2);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
Collection<ScoredEntry<RBucket<String>>> entryRange = b1.entryRange(0, 1);
Assertions.assertEquals(b2.get(), entryRange.iterator().next().getValue().get());
}
@Test
public void testReadAll() throws InterruptedException {
RSetCache<RBucket<String>> b1 = redisson.getSetCache("set");
RBucket<String> b2 = redisson.getBucket("bucket");
b1.add(b2, 1, TimeUnit.MINUTES);
b2.set("test1");
Assertions.assertEquals(b2.get(), b1.readAll().iterator().next().get());
Assertions.assertEquals(2, redisson.getKeys().count());
RMapCache<String, RSetCache<RBucket<String>>> b3 = redisson.getMapCache("map");
b3.put("1", b1);
Assertions.assertEquals(b2.get(), b3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), b3.readAllValues().iterator().next().iterator().next().get());
RMapCache<RBucket<String>, RSetCache<RBucket<String>>> b4 = redisson.getMapCache("map1");
b4.put(b2, b1);
Assertions.assertEquals(b2.get(), b4. [MASK] ().iterator().next().get());
RPriorityQueue<RBucket<String>> q1 = redisson.getPriorityQueue("q1");
q1.add(b2);
Assertions.assertEquals(b2.get(), q1.readAll().get(0).get());
RQueue<RBucket<String>> q2 = redisson.getQueue("q2");
q2.add(b2);
Assertions.assertEquals(b2.get(), q2.readAll().get(0).get());
RDelayedQueue<RBucket<String>> q3 = redisson.getDelayedQueue(q2);
q3.offer(b2, 10, TimeUnit.MINUTES);
Assertions.assertEquals(b2.get(), q3.readAll().get(0).get());
RList<RBucket<String>> l1 = redisson.getList("l1");
l1.add(b2);
Assertions.assertEquals(b2.get(), l1.readAll().get(0).get());
RList<RBucket<String>> sl1 = l1.subList(0, 0);
Assertions.assertEquals(b2.get(), sl1.readAll().get(0).get());
RLocalCachedMap<String, RBucket<String>> m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
m1.put("1", b2);
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
m1 = redisson.getLocalCachedMap("m1", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m1.readAllMap().get("1").get());
Assertions.assertEquals(b2.get(), m1.readAllEntrySet().iterator().next().getValue().get());
Assertions.assertEquals(b2.get(), m1.readAllValues().iterator().next().get());
RLocalCachedMap<RBucket<String>, RBucket<String>> m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
m2.put(b2, b2);
Assertions.assertEquals(b2.get(), m2. [MASK] ().iterator().next().get());
m2 = redisson.getLocalCachedMap("m2", LocalCachedMapOptions.defaults());
Assertions.assertEquals(b2.get(), m2. [MASK] ().iterator().next().get());
RMap<String, RSetCache<RBucket<String>>> m3 = redisson.getMap("m3");
m3.put("1", b1);
Assertions.assertEquals(b2.get(), m3.readAllMap().get("1").iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllEntrySet().iterator().next().getValue().iterator().next().get());
Assertions.assertEquals(b2.get(), m3.readAllValues().iterator().next().iterator().next().get());
RMap<RBucket<String>, RSetCache<RBucket<String>>> m4 = redisson.getMap("m4");
m4.put(b2, b1);
Assertions.assertEquals(b2.get(), m4. [MASK] ().iterator().next().get());
//multimap
RGeo<RBucket<String>> g1 = redisson.getGeo("g1");
g1.add(13.361389, 38.115556, b2);
Assertions.assertEquals(b2.get(), g1.readAll().iterator().next().get());
RScoredSortedSet<RBucket<String>> s1 = redisson.getScoredSortedSet("s1");
s1.add(0.0, b2);
Assertions.assertEquals(b2.get(), s1.readAll().iterator().next().get());
RListMultimap<String, RBucket<String>> mm1 = redisson.getListMultimap("mm1");
mm1.put("1", b2);
Assertions.assertEquals(b2.get(), mm1.get("1").readAll().get(0).get());
RListMultimap<RBucket<String>, RBucket<String>> mm2 = redisson.getListMultimap("mm2");
mm2.put(b2, b2);
Assertions.assertEquals(b2.get(), mm2.get(b2).readAll().get(0).get());
RSetMultimap<String, RBucket<String>> mm3 = redisson.getSetMultimap("mm3");
mm3.put("1", b2);
Assertions.assertEquals(b2.get(), mm3.get("1").readAll().iterator().next().get());
RSetMultimap<RBucket<String>, RBucket<String>> mm4 = redisson.getSetMultimap("mm4");
mm4.put(b2, b2);
Assertions.assertEquals(b2.get(), mm4.get(b2).readAll().iterator().next().get());
}
@Test
public void testWithMap() {
RMap<RBucket<RMap>, RBucket<RMap>> map = redisson.getMap("set");
RBucket<RMap> b1 = redisson.getBucket("bucket1");
RBucket<RMap> b2 = redisson.getBucket("bucket2");
map.put(b1, b2);
Assertions.assertEquals(b2.get(), map.values().iterator().next().get());
Assertions.assertEquals(b1.get(), map.keySet().iterator().next().get());
Assertions.assertNotEquals(3, redisson.getKeys().count());
Assertions.assertEquals(1, redisson.getKeys().count());
b1.set(map);
b2.set(map);
Assertions.assertNotEquals(1, redisson.getKeys().count());
Assertions.assertEquals(3, redisson.getKeys().count());
}
@Test
public void shouldUseDefaultCodec() {
Config config = new Config();
Codec codec = new Kryo5Codec();
config.setCodec(codec);
config.useSingleServer()
.setAddress(redisson.getConfig().useSingleServer().getAddress());
RedissonClient redissonClient = Redisson.create(config);
RBucket<Object> b1 = redissonClient.getBucket("b1");
b1.set(new MyObject());
RSet<Object> s1 = redissonClient.getSet("s1");
Assertions.assertTrue(s1.add(b1));
Assertions.assertTrue(codec == b1.getCodec());
RedissonClient redissonClient1 = Redisson.create(config);
RSet<RBucket> s2 = redissonClient1.getSet("s1");
RBucket<MyObject> b2 = s2.iterator(1).next();
Assertions.assertTrue(codec == b2.getCodec());
Assertions.assertTrue(b2.get() instanceof MyObject);
redissonClient.shutdown();
redissonClient1.shutdown();
}
public static class MyObject {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
| readAllKeySet |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi. [MASK] ;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record [MASK] s(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static [MASK] s get [MASK] s(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return get [MASK] s(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static [MASK] s get [MASK] s(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
[MASK] Calculator argCalc = forUpcall ? new Box [MASK] Calculator(true) : new Unbox [MASK] Calculator(true, options.allowsHeapAccess());
[MASK] Calculator retCalc = forUpcall ? new Unbox [MASK] Calculator(false, false) : new Box [MASK] Calculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgument [MASK] s(carrier, layout, argCalc.get [MASK] s(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturn [MASK] s(carrier, layout, retCalc.get [MASK] s(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgument [MASK] s(carrier, layout, argCalc.get [MASK] s(carrier, layout));
}
return new [MASK] s(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
[MASK] s bindings = get [MASK] s(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
[MASK] s bindings = get [MASK] s(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class [MASK] Calculator {
protected final StorageCalculator storageCalculator;
protected [MASK] Calculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List< [MASK] > get [MASK] s(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class Unbox [MASK] Calculator extends [MASK] Calculator {
private final boolean useAddressPairs;
Unbox [MASK] Calculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List< [MASK] > get [MASK] s(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
[MASK] .Builder bindings = [MASK] .builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class Box [MASK] Calculator extends [MASK] Calculator {
Box [MASK] Calculator(boolean forArguments) {
super(forArguments);
}
@Override
List< [MASK] > get [MASK] s(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
[MASK] .Builder bindings = [MASK] .builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for Box [MASK] Calculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| Binding |
package com.gateway.web.rest.errors;
import com.gateway.IntegrationTest;
import org.hamcrest.core.AnyOf;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* Integration tests {@link ExceptionTranslator} controller advice.
*/
@WithMockUser
@AutoConfigureWebTestClient(timeout = IntegrationTest.DEFAULT_TIMEOUT)
@IntegrationTest
class ExceptionTranslatorIT {
@Autowired
private WebTestClient webTestClient;
@Test
void testConcurrencyFailure() {
webTestClient
.get()
.uri("/api/exception-translator-test/concurrency-failure")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.CONFLICT)
.expectHeader()
. [MASK] (MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo(ErrorConstants.ERR_CONCURRENCY_FAILURE);
}
@Test
void testMethodArgumentNotValid() {
webTestClient
.post()
.uri("/api/exception-translator-test/method-argument")
. [MASK] (MediaType.APPLICATION_JSON)
.bodyValue("{}")
.exchange()
.expectHeader()
. [MASK] (MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo(ErrorConstants.ERR_VALIDATION)
.jsonPath("$.fieldErrors.[0].objectName")
.isEqualTo("test")
.jsonPath("$.fieldErrors.[0].field")
.isEqualTo("test")
.jsonPath("$.fieldErrors.[0].message")
.isEqualTo("must not be null");
}
@Test
void testMissingRequestPart() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-part")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
. [MASK] (MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400");
}
@Test
void testMissingRequestParameter() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-parameter")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
. [MASK] (MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400");
}
@Test
void testAccessDenied() {
webTestClient
.get()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isForbidden()
.expectHeader()
. [MASK] (MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.403")
.jsonPath("$.detail")
.isEqualTo("test access denied!");
}
@Test
void testUnauthorized() {
webTestClient
.get()
.uri("/api/exception-translator-test/unauthorized")
.exchange()
.expectStatus()
.isUnauthorized()
.expectHeader()
. [MASK] (MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.401")
.jsonPath("$.path")
.isEqualTo("/api/exception-translator-test/unauthorized")
.jsonPath("$.detail")
.value(AnyOf.anyOf(IsEqual.equalTo("test authentication failed!"), IsEqual.equalTo("Invalid credentials")));
}
@Test
void testMethodNotSupported() {
webTestClient
.post()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.METHOD_NOT_ALLOWED)
.expectHeader()
. [MASK] (MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.405")
.jsonPath("$.detail")
.isEqualTo("405 METHOD_NOT_ALLOWED \"Request method 'POST' is not supported.\"");
}
@Test
void testExceptionWithResponseStatus() {
webTestClient
.get()
.uri("/api/exception-translator-test/response-status")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
. [MASK] (MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400")
.jsonPath("$.title")
.isEqualTo("test response status");
}
@Test
void testInternalServerError() {
webTestClient
.get()
.uri("/api/exception-translator-test/internal-server-error")
.exchange()
.expectHeader()
. [MASK] (MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.500")
.jsonPath("$.title")
.isEqualTo("Internal Server Error");
}
}
| contentType |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean [MASK] = isInMemoryReturn(cDesc.returnLayout());
if ( [MASK] ) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), [MASK] );
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| returnInMemory |
/**
* Copyright (c) 2013-2024 Nikita Koksharov
*
* 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 org.redisson. [MASK] .strategy;
import org. [MASK] .cache.CacheException;
import org. [MASK] .cache.internal.DefaultCacheKeysFactory;
import org. [MASK] .cache.spi.EntityRegion;
import org. [MASK] .cache.spi.GeneralDataRegion;
import org. [MASK] .cache.spi.access.EntityRegionAccessStrategy;
import org. [MASK] .cache.spi.access.SoftLock;
import org. [MASK] .cfg.Settings;
import org. [MASK] .engine.spi.SessionFactoryImplementor;
import org. [MASK] .engine.spi.SessionImplementor;
import org. [MASK] .persister.entity.EntityPersister;
import org.redisson. [MASK] .region.RedissonEntityRegion;
/**
*
* @author Nikita Koksharov
*
*/
public class ReadOnlyEntityRegionAccessStrategy extends BaseRegionAccessStrategy implements EntityRegionAccessStrategy {
public ReadOnlyEntityRegionAccessStrategy(Settings settings, GeneralDataRegion region) {
super(settings, region);
}
@Override
public Object get(SessionImplementor session, Object key, long txTimestamp) throws CacheException {
return region.get(session, key);
}
@Override
public boolean putFromLoad(SessionImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride)
throws CacheException {
if (minimalPutOverride && region.contains(key)) {
return false;
}
region.put(session, key, value);
return true;
}
@Override
public SoftLock lockItem(SessionImplementor session, Object key, Object version) throws CacheException {
return null;
}
@Override
public void unlockItem(SessionImplementor session, Object key, SoftLock lock) throws CacheException {
evict(key);
}
@Override
public EntityRegion getRegion() {
return (EntityRegion) region;
}
@Override
public boolean insert(SessionImplementor session, Object key, Object value, Object version) throws CacheException {
return false;
}
@Override
public boolean afterInsert(SessionImplementor session, Object key, Object value, Object version) throws CacheException {
region.put(session, key, value);
return true;
}
@Override
public boolean update(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion)
throws CacheException {
throw new UnsupportedOperationException("Unable to update read-only object");
}
@Override
public boolean afterUpdate(SessionImplementor session, Object key, Object value, Object currentVersion, Object previousVersion, SoftLock lock)
throws CacheException {
throw new UnsupportedOperationException("Unable to update read-only object");
}
@Override
public Object generateCacheKey(Object id, EntityPersister persister, SessionFactoryImplementor factory, String tenantIdentifier) {
return ((RedissonEntityRegion)region).getCacheKeysFactory().createEntityKey( id, persister, factory, tenantIdentifier );
}
@Override
public Object getCacheKeyId(Object cacheKey) {
return ((RedissonEntityRegion)region).getCacheKeysFactory().getEntityId(cacheKey);
}
}
| hibernate |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage [MASK] (long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
[MASK] (4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = [MASK] (4, 4);
} else
stack = [MASK] (8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| stackAlloc |
package com.gateway.web.rest.errors;
import com.gateway.IntegrationTest;
import org.hamcrest.core.AnyOf;
import org.hamcrest.core. [MASK] ;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* Integration tests {@link ExceptionTranslator} controller advice.
*/
@WithMockUser
@AutoConfigureWebTestClient(timeout = IntegrationTest.DEFAULT_TIMEOUT)
@IntegrationTest
class ExceptionTranslatorIT {
@Autowired
private WebTestClient webTestClient;
@Test
void testConcurrencyFailure() {
webTestClient
.get()
.uri("/api/exception-translator-test/concurrency-failure")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.CONFLICT)
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo(ErrorConstants.ERR_CONCURRENCY_FAILURE);
}
@Test
void testMethodArgumentNotValid() {
webTestClient
.post()
.uri("/api/exception-translator-test/method-argument")
.contentType(MediaType.APPLICATION_JSON)
.bodyValue("{}")
.exchange()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo(ErrorConstants.ERR_VALIDATION)
.jsonPath("$.fieldErrors.[0].objectName")
.isEqualTo("test")
.jsonPath("$.fieldErrors.[0].field")
.isEqualTo("test")
.jsonPath("$.fieldErrors.[0].message")
.isEqualTo("must not be null");
}
@Test
void testMissingRequestPart() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-part")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400");
}
@Test
void testMissingRequestParameter() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-parameter")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400");
}
@Test
void testAccessDenied() {
webTestClient
.get()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isForbidden()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.403")
.jsonPath("$.detail")
.isEqualTo("test access denied!");
}
@Test
void testUnauthorized() {
webTestClient
.get()
.uri("/api/exception-translator-test/unauthorized")
.exchange()
.expectStatus()
.isUnauthorized()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.401")
.jsonPath("$.path")
.isEqualTo("/api/exception-translator-test/unauthorized")
.jsonPath("$.detail")
.value(AnyOf.anyOf( [MASK] .equalTo("test authentication failed!"), [MASK] .equalTo("Invalid credentials")));
}
@Test
void testMethodNotSupported() {
webTestClient
.post()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.METHOD_NOT_ALLOWED)
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.405")
.jsonPath("$.detail")
.isEqualTo("405 METHOD_NOT_ALLOWED \"Request method 'POST' is not supported.\"");
}
@Test
void testExceptionWithResponseStatus() {
webTestClient
.get()
.uri("/api/exception-translator-test/response-status")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400")
.jsonPath("$.title")
.isEqualTo("test response status");
}
@Test
void testInternalServerError() {
webTestClient
.get()
.uri("/api/exception-translator-test/internal-server-error")
.exchange()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.500")
.jsonPath("$.title")
.isEqualTo("Internal Server Error");
}
}
| IsEqual |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean [MASK] ;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean [MASK] ) {
this. [MASK] = [MASK] ;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = ( [MASK] ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean [MASK] ) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator( [MASK] );
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean [MASK] , boolean useAddressPairs) {
super( [MASK] );
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean [MASK] ) {
super( [MASK] );
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| forArguments |
package com.gateway.web.rest.errors;
import com.gateway. [MASK] ;
import org.hamcrest.core.AnyOf;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* Integration tests {@link ExceptionTranslator} controller advice.
*/
@WithMockUser
@AutoConfigureWebTestClient(timeout = [MASK] .DEFAULT_TIMEOUT)
@ [MASK]
class ExceptionTranslatorIT {
@Autowired
private WebTestClient webTestClient;
@Test
void testConcurrencyFailure() {
webTestClient
.get()
.uri("/api/exception-translator-test/concurrency-failure")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.CONFLICT)
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo(ErrorConstants.ERR_CONCURRENCY_FAILURE);
}
@Test
void testMethodArgumentNotValid() {
webTestClient
.post()
.uri("/api/exception-translator-test/method-argument")
.contentType(MediaType.APPLICATION_JSON)
.bodyValue("{}")
.exchange()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo(ErrorConstants.ERR_VALIDATION)
.jsonPath("$.fieldErrors.[0].objectName")
.isEqualTo("test")
.jsonPath("$.fieldErrors.[0].field")
.isEqualTo("test")
.jsonPath("$.fieldErrors.[0].message")
.isEqualTo("must not be null");
}
@Test
void testMissingRequestPart() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-part")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400");
}
@Test
void testMissingRequestParameter() {
webTestClient
.get()
.uri("/api/exception-translator-test/missing-servlet-request-parameter")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400");
}
@Test
void testAccessDenied() {
webTestClient
.get()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isForbidden()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.403")
.jsonPath("$.detail")
.isEqualTo("test access denied!");
}
@Test
void testUnauthorized() {
webTestClient
.get()
.uri("/api/exception-translator-test/unauthorized")
.exchange()
.expectStatus()
.isUnauthorized()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.401")
.jsonPath("$.path")
.isEqualTo("/api/exception-translator-test/unauthorized")
.jsonPath("$.detail")
.value(AnyOf.anyOf(IsEqual.equalTo("test authentication failed!"), IsEqual.equalTo("Invalid credentials")));
}
@Test
void testMethodNotSupported() {
webTestClient
.post()
.uri("/api/exception-translator-test/access-denied")
.exchange()
.expectStatus()
.isEqualTo(HttpStatus.METHOD_NOT_ALLOWED)
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.405")
.jsonPath("$.detail")
.isEqualTo("405 METHOD_NOT_ALLOWED \"Request method 'POST' is not supported.\"");
}
@Test
void testExceptionWithResponseStatus() {
webTestClient
.get()
.uri("/api/exception-translator-test/response-status")
.exchange()
.expectStatus()
.isBadRequest()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.400")
.jsonPath("$.title")
.isEqualTo("test response status");
}
@Test
void testInternalServerError() {
webTestClient
.get()
.uri("/api/exception-translator-test/internal-server-error")
.exchange()
.expectHeader()
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
.expectBody()
.jsonPath("$.message")
.isEqualTo("error.http.500")
.jsonPath("$.title")
.isEqualTo("Internal Server Error");
}
}
| IntegrationTest |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi. [MASK] ;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, [MASK] .empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, [MASK] options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, [MASK] options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, [MASK] options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator storageCalculator;
protected BindingCalculator(boolean forArguments) {
this.storageCalculator = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = storageCalculator.getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = storageCalculator.getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| LinkerOptions |
/*
* Copyright (c) 1998, 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.
*
* 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.
*/
/* @test
@bug 4092350
@summary Verify that reads and writes of primitives are correct
*/
// The bug mentioned is actually a performance bug that prompted
// changes in the methods to write primitives
import java.io.*;
import java.io.*;
public class ReadWritePrimitives {
public static void main(String args[]) throws IOException {
long start, finish;
start = System.currentTimeMillis();
testShort();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
start = System.currentTimeMillis();
testChar();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
start = System.currentTimeMillis();
testInt();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
start = System.currentTimeMillis();
testLong();
finish = System.currentTimeMillis();
// System.err.println("Time taken="+(finish-start));
}
private static void testShort() throws IOException {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeShort((short)i);
}
f.writeShort((short)65535);
f. [MASK] ();
f = new RandomAccessFile(fh,"r");
for(int i = 0; i < 10000; i++) {
short r = f.readShort();
if (r != ((short)i)) {
System.err.println("An error occurred. Read:" + r
+ " i:" + ((short)i));
throw new IOException("Bad read from a writeShort");
}
}
short rmax = f.readShort();
if (rmax != ((short)65535)) {
System.err.println("An error occurred. Read:" + rmax);
throw new IOException("Bad read from a writeShort");
}
f. [MASK] ();
}
private static void testChar() throws IOException {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeChar((char)i);
}
f. [MASK] ();
f = new RandomAccessFile(fh,"r");
for(int i = 0; i < 10000; i++) {
char r = f.readChar();
if (r != ((char)i)){
System.err.println("An error occurred. Read:" + r
+ " i:" + ((char) i));
throw new IOException("Bad read from a writeChar");
}
}
f. [MASK] ();
}
private static void testInt() throws IOException {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeInt((short)i);
}
f.writeInt(Integer.MAX_VALUE);
f. [MASK] ();
f = new RandomAccessFile(fh, "r");
for(int i = 0; i < 10000; i++) {
int r = f.readInt();
if (r != i){
System.err.println("An error occurred. Read:" + r
+ " i:" + i);
throw new IOException("Bad read from a writeInt");
}
}
int rmax = f.readInt();
if (rmax != Integer.MAX_VALUE){
System.err.println("An error occurred. Read:" + rmax);
throw new IOException("Bad read from a writeInt");
}
f. [MASK] ();
}
private static void testLong() throws IOException {
File fh = new File(System.getProperty("test.dir", "."),
"x.ReadWriteGenerated");
RandomAccessFile f = new RandomAccessFile(fh,"rw");
for(int i = 0; i < 10000; i++){
f.writeLong(123456789L * (long)i);
}
f. [MASK] ();
f = new RandomAccessFile(fh,"r");
for(int i = 0; i < 10000; i++){
long r = f.readLong();
if (r != (((long) i) * 123456789L) ) {
System.err.println("An error occurred. Read:" + r
+ " i" + ((long) i));
throw new IOException("Bad read from a writeInt");
}
}
f. [MASK] ();
}
}
| close |
/*
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023 IBM Corp. 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.foreign.abi.s390.linux;
import jdk.internal.foreign.Utils;
import jdk.internal.foreign.abi.ABIDescriptor;
import jdk.internal.foreign.abi.AbstractLinker.UpcallStubFactory;
import jdk.internal.foreign.abi.Binding;
import jdk.internal.foreign.abi.CallingSequence;
import jdk.internal.foreign.abi.CallingSequenceBuilder;
import jdk.internal.foreign.abi.DowncallLinker;
import jdk.internal.foreign.abi.LinkerOptions;
import jdk.internal.foreign.abi.SharedUtils;
import jdk.internal.foreign.abi.VMStorage;
import java.lang.foreign.AddressLayout;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.GroupLayout;
import java.lang.foreign.MemoryLayout;
import java.lang.foreign.MemorySegment;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.util.List;
import java.util.Optional;
import static jdk.internal.foreign.abi.s390.S390Architecture.*;
import static jdk.internal.foreign.abi.s390.S390Architecture.Regs.*;
/**
* For the S390 C ABI specifically, this class uses CallingSequenceBuilder
* to translate a C FunctionDescriptor into a CallingSequence, which can then be turned into a MethodHandle.
*
* This includes taking care of synthetic arguments like pointers to return buffers for 'in-memory' returns.
*/
public class LinuxS390CallArranger {
private static final int STACK_SLOT_SIZE = 8;
public static final int MAX_REGISTER_ARGUMENTS = 5;
public static final int MAX_FLOAT_REGISTER_ARGUMENTS = 4;
private static final ABIDescriptor CLinux = abiFor(
new VMStorage[] { r2, r3, r4, r5, r6, }, // GP input
new VMStorage[] { f0, f2, f4, f6 }, // FP input
new VMStorage[] { r2, }, // GP output
new VMStorage[] { f0, }, // FP output
new VMStorage[] { r0, r1, r2, r3, r4, r5, r14 }, // volatile GP
new VMStorage[] { f1, f3, f5, f7 }, // volatile FP (excluding argument registers)
8, // Stack is always 8 byte aligned on S390
160, // ABI header
r0, r1 // scratch reg r0 & r1
);
public record Bindings(CallingSequence callingSequence, boolean isInMemoryReturn) {}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall) {
return getBindings(mt, cDesc, forUpcall, LinkerOptions.empty());
}
public static Bindings getBindings(MethodType mt, FunctionDescriptor cDesc, boolean forUpcall, LinkerOptions options) {
CallingSequenceBuilder csb = new CallingSequenceBuilder(CLinux, forUpcall, options);
BindingCalculator argCalc = forUpcall ? new BoxBindingCalculator(true) : new UnboxBindingCalculator(true, options.allowsHeapAccess());
BindingCalculator retCalc = forUpcall ? new UnboxBindingCalculator(false, false) : new BoxBindingCalculator(false);
boolean returnInMemory = isInMemoryReturn(cDesc.returnLayout());
if (returnInMemory) {
Class<?> carrier = MemorySegment.class;
MemoryLayout layout =SharedUtils.C_POINTER;
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
} else if (cDesc.returnLayout().isPresent()) {
Class<?> carrier = mt.returnType();
MemoryLayout layout = cDesc.returnLayout().get();
csb.setReturnBindings(carrier, layout, retCalc.getBindings(carrier, layout));
}
for (int i = 0; i < mt.parameterCount(); i++) {
Class<?> carrier = mt.parameterType(i);
MemoryLayout layout = cDesc.argumentLayouts().get(i);
csb.addArgumentBindings(carrier, layout, argCalc.getBindings(carrier, layout));
}
return new Bindings(csb.build(), returnInMemory);
}
public static MethodHandle arrangeDowncall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, false, options);
MethodHandle handle = new DowncallLinker(CLinux, bindings.callingSequence).getBoundMethodHandle();
if (bindings.isInMemoryReturn) {
handle = SharedUtils.adaptDowncallForIMR(handle, cDesc, bindings.callingSequence);
}
return handle;
}
public static UpcallStubFactory arrangeUpcall(MethodType mt, FunctionDescriptor cDesc, LinkerOptions options) {
Bindings bindings = getBindings(mt, cDesc, true, options);
final boolean dropReturn = true; /* drop return, since we don't have bindings for it */
return SharedUtils.arrangeUpcallHelper(mt, bindings.isInMemoryReturn, dropReturn, CLinux,
bindings.callingSequence);
}
private static boolean isInMemoryReturn(Optional<MemoryLayout> returnLayout) {
return returnLayout
.filter(layout -> layout instanceof GroupLayout)
.isPresent();
}
static class StorageCalculator {
private final boolean forArguments;
private final int[] nRegs = new int[] { 0, 0 };
private long stackOffset = 0;
public StorageCalculator(boolean forArguments) {
this.forArguments = forArguments;
}
VMStorage stackAlloc(long size, long alignment) {
long alignedStackOffset = Utils.alignUp(stackOffset, alignment);
short encodedSize = (short) size;
assert (encodedSize & 0xFFFF) == size;
VMStorage storage = stackStorage(encodedSize, (int) alignedStackOffset);
stackOffset = alignedStackOffset + size;
return storage;
}
VMStorage regAlloc(int type) {
int gpRegCnt = (type == StorageType.INTEGER) ? 1 : 0;
int fpRegCnt = (type == StorageType.FLOAT) ? 1 : 0;
// Use stack if not enough registers available.
if ((type == StorageType.FLOAT && (nRegs[StorageType.FLOAT] + fpRegCnt) > MAX_FLOAT_REGISTER_ARGUMENTS)
|| (type == StorageType.INTEGER && (nRegs[StorageType.INTEGER] + gpRegCnt) > MAX_REGISTER_ARGUMENTS)) return null;
VMStorage[] source = (forArguments ? CLinux.inputStorage : CLinux.outputStorage)[type];
VMStorage result = source[nRegs[type]];
nRegs[StorageType.INTEGER] += gpRegCnt;
nRegs[StorageType.FLOAT] += fpRegCnt;
return result;
}
VMStorage getStorage(int type, boolean is32Bit) {
VMStorage reg = regAlloc(type);
if (reg != null) {
if (is32Bit) {
reg = new VMStorage(reg.type(), REG32_MASK, reg.indexOrOffset());
}
return reg;
}
VMStorage stack;
if (is32Bit) {
stackAlloc(4, STACK_SLOT_SIZE); // Skip first half of stack slot.
stack = stackAlloc(4, 4);
} else
stack = stackAlloc(8, STACK_SLOT_SIZE);
return stack;
}
}
abstract static class BindingCalculator {
protected final StorageCalculator [MASK] ;
protected BindingCalculator(boolean forArguments) {
this. [MASK] = new LinuxS390CallArranger.StorageCalculator(forArguments);
}
abstract List<Binding> getBindings(Class<?> carrier, MemoryLayout layout);
}
// Compute recipe for transferring arguments / return values to C from Java.
static class UnboxBindingCalculator extends BindingCalculator {
private final boolean useAddressPairs;
UnboxBindingCalculator(boolean forArguments, boolean useAddressPairs) {
super(forArguments);
this.useAddressPairs = useAddressPairs;
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
VMStorage storage = [MASK] .getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
VMStorage storage = [MASK] .getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.bufferLoad(0, type)
.vmStore(storage, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
bindings.copy(layout)
.unboxAddress();
VMStorage storage = [MASK] .getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, long.class);
}
case POINTER -> {
VMStorage storage = [MASK] .getStorage(StorageType.INTEGER, false);
if (useAddressPairs) {
bindings.dup()
.segmentBase()
.vmStore(storage, Object.class)
.segmentOffsetAllowHeap()
.vmStore(null, long.class);
} else {
bindings.unboxAddress();
bindings.vmStore(storage, long.class);
}
}
case INTEGER -> {
// ABI requires all int types to get extended to 64 bit.
VMStorage storage = [MASK] .getStorage(StorageType.INTEGER, false);
bindings.vmStore(storage, carrier);
}
case FLOAT -> {
VMStorage storage = [MASK] .getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmStore(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
// Compute recipe for transferring arguments / return values from C to Java.
static class BoxBindingCalculator extends BindingCalculator {
BoxBindingCalculator(boolean forArguments) {
super(forArguments);
}
@Override
List<Binding> getBindings(Class<?> carrier, MemoryLayout layout) {
TypeClass argumentClass = TypeClass.classifyLayout(layout);
Binding.Builder bindings = Binding.builder();
switch (argumentClass) {
case STRUCT_REGISTER -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = [MASK] .getStorage(StorageType.INTEGER, false);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), false);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_SFA -> {
assert carrier == MemorySegment.class;
bindings.allocate(layout)
.dup();
VMStorage storage = [MASK] .getStorage(StorageType.FLOAT, layout.byteSize() == 4);
Class<?> type = SharedUtils.primitiveCarrierForSize(layout.byteSize(), true);
bindings.vmLoad(storage, type)
.bufferStore(0, type);
}
case STRUCT_REFERENCE -> {
assert carrier == MemorySegment.class;
VMStorage storage = [MASK] .getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddress(layout);
}
case POINTER -> {
AddressLayout addressLayout = (AddressLayout) layout;
VMStorage storage = [MASK] .getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, long.class)
.boxAddressRaw(Utils.pointeeByteSize(addressLayout), Utils.pointeeByteAlign(addressLayout));
}
case INTEGER -> {
// We could use carrier != long.class for BoxBindingCalculator, but C always uses 64 bit slots.
VMStorage storage = [MASK] .getStorage(StorageType.INTEGER, false);
bindings.vmLoad(storage, carrier);
}
case FLOAT -> {
VMStorage storage = [MASK] .getStorage(StorageType.FLOAT, carrier == float.class);
bindings.vmLoad(storage, carrier);
}
default -> throw new UnsupportedOperationException("Unhandled class " + argumentClass);
}
return bindings.build();
}
}
}
| storageCalculator |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.