-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix potential seg fault during pixel op
- Loading branch information
1 parent
bf7fb76
commit cf0ce9c
Showing
2 changed files
with
162 additions
and
52 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
68 changes: 68 additions & 0 deletions
68
core/src/test/java/icyllis/modernui/test/TestHighConcurrencyBitmap.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,68 @@ | ||
/* | ||
* Modern UI. | ||
* Copyright (C) 2024 BloCamLimb. All rights reserved. | ||
* | ||
* Modern UI is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* Modern UI 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 Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with Modern UI. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package icyllis.modernui.test; | ||
|
||
import icyllis.modernui.graphics.Bitmap; | ||
import org.openjdk.jmh.annotations.*; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.RunnerException; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
import java.util.Random; | ||
|
||
@Fork(2) | ||
@Threads(16) | ||
@Warmup(iterations = 2, time = 1) | ||
@Measurement(iterations = 5, time = 1) | ||
@State(Scope.Thread) | ||
public class TestHighConcurrencyBitmap { | ||
|
||
public static void main(String[] args) throws RunnerException { | ||
// you will get seg fault if there is no reachabilityFence() in the Bitmap class | ||
new Runner(new OptionsBuilder() | ||
.include(TestHighConcurrencyBitmap.class.getSimpleName()) | ||
.shouldFailOnError(true).shouldDoGC(true) | ||
.jvmArgs("-Xmx128m", "-Dorg.lwjgl.system.allocator=system") | ||
.build()) | ||
.run(); | ||
} | ||
|
||
private static final Bitmap SRC; | ||
|
||
static { | ||
Bitmap bm = Bitmap.createBitmap(32, 32, Bitmap.Format.RGBA_F32); | ||
Random r = new Random(); | ||
for (int i = 0; i < 32; i++) { | ||
for (int j = 0; j < 32; j++) { | ||
bm.setColor4f(i, j, new float[]{r.nextFloat(), r.nextFloat(), r.nextFloat(), r.nextFloat()}); | ||
} | ||
} | ||
SRC = bm; | ||
} | ||
|
||
@Benchmark | ||
public static void testRWPixel(Blackhole blackhole) { | ||
blackhole.consume(new Object()); | ||
@SuppressWarnings("resource") | ||
var bm = Bitmap.createBitmap(32, 32, Bitmap.Format.RGBA_8888); | ||
bm.setPixels(SRC, 0, 0, 0, 0, 32, 32); | ||
blackhole.consume(new Object()); | ||
} | ||
} |