GlueGen: src/junit/com/jogamp/common/util/TestUnsafeUtil.java Source File

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() {
50 Platform.initSingleton();
51 }
52
53 @Test
54 public void testWithoutIllegalAccessLogger00() {
55 if( ! UnsafeUtil.hasIllegalAccessLoggerAccess() ) {
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}
com.jogamp.common.nio.Buffers
Utility methods allowing easy java.nio.Buffer manipulations.
Definition: Buffers.java:70
com.jogamp.common.nio.Buffers.getDirectBufferAddress
static long getDirectBufferAddress(final Object directBuffer)
Definition: Buffers.java:2086
com.jogamp.common.nio.Buffers.newDirectByteBuffer
static ByteBuffer newDirectByteBuffer(final int numElements)
Allocates a new direct ByteBuffer with the specified number of elements.
Definition: Buffers.java:92
com.jogamp.common.os.Platform
Utility class for querying platform specific properties.
Definition: Platform.java:58
com.jogamp.common.os.Platform.initSingleton
static void initSingleton()
kick off static initialization of platform property information and native gluegen_rt lib loading
Definition: Platform.java:359
com.jogamp.common.util.TestUnsafeUtil
Definition: TestUnsafeUtil.java:46
com.jogamp.common.util.TestUnsafeUtil.testWithoutIllegalAccessLogger00
void testWithoutIllegalAccessLogger00()
Definition: TestUnsafeUtil.java:54
com.jogamp.common.util.TestUnsafeUtil.init
static void init()
Definition: TestUnsafeUtil.java:49
com.jogamp.common.util.TestUnsafeUtil.main
static void main(final String args[])
Definition: TestUnsafeUtil.java:75
com.jogamp.common.util.TestUnsafeUtil.test01
void test01()
Definition: TestUnsafeUtil.java:68
com.jogamp.common.util.UnsafeUtil
Utility methods allowing easy access to certain sun.misc.Unsafe functionality.
Definition: UnsafeUtil.java:46
com.jogamp.common.util.UnsafeUtil.hasIllegalAccessLoggerAccess
static boolean hasIllegalAccessLoggerAccess()
Returns true if access to jdk.internal.module.IllegalAcessLogger's logger field is available and has ...
Definition: UnsafeUtil.java:340
com.jogamp.common.util.UnsafeUtil.getDirectBufferAddress
static long getDirectBufferAddress(final Buffer buffer)
Definition: UnsafeUtil.java:325
com.jogamp.common.util.UnsafeUtil.doWithoutIllegalAccessLogger
static< T > T doWithoutIllegalAccessLogger(final PrivilegedAction< T > action)
Issue the given user action while jdk.internal.module.IllegalAcessLogger's logger has been temporaril...
Definition: UnsafeUtil.java:355
com.jogamp.junit.util.SingletonJunitCase
Definition: SingletonJunitCase.java:39