GlueGen v2.6.0-rc-20250722
GlueGen, Native Binding Generator for Java™ (public API).
TestUnsafeUtil.java
Go to the documentation of this file.
1/**
2 * Copyright 2025 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.common.util;
30
31import java.nio.ByteBuffer;
32import java.security.PrivilegedAction;
33
34import org.junit.Assert;
35import org.junit.BeforeClass;
36import org.junit.Test;
37
38import com.jogamp.common.nio.Buffers;
39import com.jogamp.common.os.Platform;
40import com.jogamp.junit.util.SingletonJunitCase;
41
42import org.junit.FixMethodOrder;
43import org.junit.runners.MethodSorters;
44
45@FixMethodOrder(MethodSorters.NAME_ASCENDING)
46public class TestUnsafeUtil extends SingletonJunitCase {
47
48 @BeforeClass
49 public static void init() {
51 }
52
53 @Test
56 return;
57 }
58 final Boolean res = UnsafeUtil.doWithoutIllegalAccessLogger(new PrivilegedAction<Boolean>() {
59 @Override
60 public Boolean run() {
61 return Boolean.TRUE;
62 }
63 });
64 Assert.assertEquals(Boolean.TRUE, res);
65 }
66
67 @Test
68 public void test01() {
69 final ByteBuffer bb = Buffers.newDirectByteBuffer(100);
70 final long a0 = UnsafeUtil.getDirectBufferAddress(bb);
71 final long a1 = Buffers.getDirectBufferAddress(bb);
72 Assert.assertEquals(a0, a1);
73 }
74
75 public static void main(final String args[]) {
76 final String tstname = TestUnsafeUtil.class.getName();
77 org.junit.runner.JUnitCore.main(tstname);
78 }
79
80}
Utility methods allowing easy java.nio.Buffer manipulations.
Definition: Buffers.java:70
static long getDirectBufferAddress(final Object directBuffer)
Definition: Buffers.java:2086
static ByteBuffer newDirectByteBuffer(final int numElements)
Allocates a new direct ByteBuffer with the specified number of elements.
Definition: Buffers.java:92
Utility class for querying platform specific properties.
Definition: Platform.java:58
static void initSingleton()
kick off static initialization of platform property information and native gluegen_rt lib loading
Definition: Platform.java:359
static void main(final String args[])
Utility methods allowing easy access to certain sun.misc.Unsafe functionality.
Definition: UnsafeUtil.java:46
static boolean hasIllegalAccessLoggerAccess()
Returns true if access to jdk.internal.module.IllegalAcessLogger's logger field is available and has ...
static long getDirectBufferAddress(final Buffer buffer)
static< T > T doWithoutIllegalAccessLogger(final PrivilegedAction< T > action)
Issue the given user action while jdk.internal.module.IllegalAcessLogger's logger has been temporaril...