-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unsafe mostly works and is used in e.g. Guava and Protobuf-Javalite
Showing
22 changed files
with
404 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
api/24/src/test/java/com/toasttab/android/Api19SignaturesTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2023. Toast Inc. | ||
* | ||
* 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.toasttab.android | ||
|
||
import org.codehaus.mojo.animal_sniffer.Clazz | ||
import org.junit.Test | ||
import strikt.api.expectThat | ||
import strikt.assertions.contains | ||
import strikt.assertions.isNotNull | ||
import java.io.File | ||
import java.io.ObjectInputStream | ||
import java.util.zip.GZIPInputStream | ||
|
||
class Api19SignaturesTest { | ||
companion object { | ||
private fun signatures(name: String) = | ||
ObjectInputStream(GZIPInputStream(File(System.getProperty(name)).inputStream())).use { | ||
generateSequence { it.readObject() as Clazz? }.toList() | ||
} | ||
|
||
private val signatures by lazy { | ||
signatures("signatures") | ||
} | ||
} | ||
|
||
@Test | ||
fun `signatures include Unsafe#getInt`() { | ||
val integer = signatures.find { it.name == "sun/misc/Unsafe" } | ||
|
||
expectThat(integer).isNotNull().and { | ||
get { signatures }.contains("getInt(Ljava/lang/Object;J)I") | ||
} | ||
} | ||
|
||
@Test | ||
fun `signatures include Unsafe#storeFence`() { | ||
val integer = signatures.find { it.name == "sun/misc/Unsafe" } | ||
|
||
expectThat(integer).isNotNull().and { | ||
get { signatures }.contains("storeFence()V") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) 2023. Toast Inc. | ||
* | ||
* 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. | ||
*/ | ||
|
||
plugins { | ||
`java-conventions` | ||
} |
90 changes: 90 additions & 0 deletions
90
sugar/unsafe/src/main/java/desugar/sun/misc/DesugarUnsafe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package desugar.sun.misc; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
public final class DesugarUnsafe { | ||
public <T> T allocateInstance(Class<T> clazz) { | ||
return null; | ||
} | ||
|
||
public int arrayBaseOffset(Class<?> clazz) { | ||
return 0; | ||
} | ||
|
||
public int arrayIndexScale(Class<?> clazz) { | ||
return 0; | ||
} | ||
|
||
public boolean compareAndSwapInt(Object obj, long offset, int expectedValue, int newValue) { | ||
return false; | ||
} | ||
|
||
public boolean compareAndSwapLong(Object obj, long offset, long expectedValue, long newValue) { | ||
return false; | ||
} | ||
|
||
public boolean compareAndSwapObject(Object obj, long offset, Object expectedValue, Object newValue) { | ||
return false; | ||
} | ||
|
||
public int getInt(Object obj, long offset) { | ||
return 0; | ||
} | ||
|
||
public int getIntVolatile(Object obj, long offset) { | ||
return 0; | ||
} | ||
|
||
public long getLong(Object obj, long offset) { | ||
return 0; | ||
} | ||
|
||
public long getLongVolatile(Object obj, long offset) { | ||
return 0; | ||
} | ||
|
||
public Object getObject(Object obj, long offset) { | ||
return null; | ||
} | ||
|
||
public Object getObjectVolatile(Object obj, long offset) { | ||
return null; | ||
} | ||
|
||
public long objectFieldOffset(Field field) { | ||
return 0; | ||
} | ||
|
||
public void park(boolean absolute, long time) { | ||
} | ||
|
||
public void unpark(Object obj) { | ||
} | ||
|
||
public void putInt(Object obj, long offset, int newValue) { | ||
} | ||
|
||
public void putIntVolatile(Object obj, long offset, int newValue) { | ||
} | ||
|
||
public void putLong(Object obj, long offset, long newValue) { | ||
} | ||
|
||
public void putLongVolatile(Object obj, long offset, long newValue) { | ||
} | ||
|
||
public void putObject(Object obj, long offset, Object newValue) { | ||
} | ||
|
||
public void putObjectVolatile(Object obj, long offset, Object newValue) { | ||
} | ||
|
||
public void putOrderedInt(Object obj, long offset, int newValue) { | ||
} | ||
|
||
public void putOrderedLong(Object obj, long offset, long newValue) { | ||
} | ||
|
||
public void putOrderedObject(Object obj, long offset, Object newValue) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) 2023. Toast Inc. | ||
* | ||
* 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. | ||
*/ | ||
|
||
plugins { | ||
`java-conventions` | ||
} |
98 changes: 98 additions & 0 deletions
98
sugar/unsafe24/src/main/java/desugar/sun/misc/DesugarUnsafe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package desugar.sun.misc; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
public final class DesugarUnsafe { | ||
public int addressSize() { | ||
return 0; | ||
} | ||
|
||
public int pageSize() { | ||
return 0; | ||
} | ||
|
||
public long allocateMemory(long bytes) { | ||
return 0; | ||
} | ||
|
||
public void freeMemory(long address) { | ||
} | ||
|
||
public void setMemory(long address, long bytes, byte value) { | ||
} | ||
|
||
public byte getByte(long address) { | ||
return 0; | ||
} | ||
|
||
public void putByte(Object obj, long offset, byte newValue) { | ||
} | ||
|
||
public short getShort(long address) { | ||
return 0; | ||
} | ||
|
||
public void putShort(Object obj, long offset, short newValue) { | ||
} | ||
|
||
public char getChar(long address) { | ||
return 0; | ||
} | ||
|
||
public void putChar(Object obj, long offset, char newValue) { | ||
} | ||
|
||
public int getInt(long address) { | ||
return 0; | ||
} | ||
|
||
public long getLong(long address) { | ||
return 0; | ||
} | ||
|
||
public float getFloat(long address) { | ||
return 0; | ||
} | ||
|
||
public void putFloat(Object obj, long offset, float newValue) { | ||
} | ||
|
||
public double getDouble(long address) { | ||
return 0; | ||
} | ||
|
||
public void putDouble(Object obj, long offset, double newValue) { | ||
} | ||
|
||
public void copyMemory(long srcAddr, long dstAddr, long bytes) { | ||
} | ||
|
||
public int getAndAddInt(Object o, long offset, int delta) { | ||
return 0; | ||
} | ||
|
||
public long getAndAddLong(Object o, long offset, long delta) { | ||
return 0; | ||
} | ||
|
||
public int getAndSetInt(Object o, long offset, int newValue) { | ||
return 0; | ||
} | ||
|
||
public long getAndSetLong(Object o, long offset, long newValue) { | ||
return 0; | ||
} | ||
|
||
public Object getAndSetObject(Object o, long offset, Object newValue) { | ||
return 0; | ||
} | ||
|
||
public void loadFence() { | ||
} | ||
|
||
public void storeFence() { | ||
} | ||
|
||
public void fullFence() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters