일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
- GPT-4's answer
- android
- NIO
- 리눅스
- 시스템
- 웹 크롤링
- chatGPT's answer
- 역학
- 고전역학
- 유닉스
- 자바네트워크
- 뉴턴역학
- write by chatGPT
- GIT
- oracle
- write by GPT-4
- 자바
- Database
- 자바암호
- 파이썬
- kotlin
- 소프트웨어공학
- lombok
- 인프라
- Spring Batch
- JVM
- Java
- Spring boot
- python
- 코틀린
- Today
- Total
Akashic Records
What is the way of Direct Memory Access in Java? 본문
What is the way of Direct Memory Access in Java?
Andrew's Akashic Records 2018. 4. 7. 22:53Java was initially designed as a safe, managed environment. Nevertheless, Java HotSpot VM contains a “backdoor” that provides a number of low-level operations to manipulate memory and threads directly.
This backdoor class – sun.misc.Unsafe – is widely used by JDK itself in packages like “java.nio” or “java.util.concurrent”. However, using this backdoor is certainly not suggested for use in the production environment, because this API is extremely dangerous, non-portable, and volatile. The Unsafe class provides an easy way to look into HotSpot JVM internals and to do some tricks. Sometimes it can be used to study VM internals without C++ code debugging, sometimes it can be leveraged for profiling and development tools.
How to use ‘sun.misc.Unsafe’
package com.blogspot.daddycat.test; import java.lang.reflect.Field; import sun.misc.Unsafe; public class UnsafeTest { public static void main(String... args) { Unsafe unsafe = null; try { Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe"); field.setAccessible(true); unsafe = (sun.misc.Unsafe) field.get(null); } catch (Exception e) { throw new AssertionError(e); } int ten = 10; byte size = 1; long mem = unsafe.allocateMemory(size); unsafe.putAddress(mem, ten); long readValue = unsafe.getAddress(mem); System.out.println("Val: " + readValue); try { Object o = unsafe.allocateInstance(java.lang.String.class); System.out.println("Type: "+o.getClass().getCanonicalName()); } catch (InstantiationException e) { e.printStackTrace(); } } } Console log Val: 10 Type: java.lang.String |
'오래된글 > Java' 카테고리의 다른 글
EJB CMP의 단점 (0) | 2018.04.07 |
---|---|
Scrolling Result Sets (0) | 2018.04.07 |
JDBC driver types (0) | 2018.04.07 |
객체 저장 : Storing Classes, Images and Other Large Objects (0) | 2018.04.07 |
Easy java Persistence (0) | 2018.04.07 |