mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2026-01-07 09:01:42 +01:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b1ad2e7fe | ||
|
|
8fd3b86ce6 | ||
|
|
08f979c5a3 | ||
|
|
add73eca25 | ||
|
|
0b84556c32 | ||
|
|
e2f9344aa7 | ||
|
|
9ff5e36e64 | ||
|
|
6306d4a603 |
@@ -25,6 +25,7 @@
|
||||
#include "precompiled.hpp"
|
||||
#include "classfile/classLoaderDataGraph.hpp"
|
||||
#include "classfile/vmSymbols.hpp"
|
||||
#include "classfile/symbolTable.hpp"
|
||||
#include "code/codeCache.hpp"
|
||||
#include "compiler/compileBroker.hpp"
|
||||
#include "gc/shared/collectedHeap.hpp"
|
||||
@@ -37,6 +38,7 @@
|
||||
#include "memory/resourceArea.hpp"
|
||||
#include "memory/universe.hpp"
|
||||
#include "oops/symbol.hpp"
|
||||
#include "oops/symbolHandle.hpp"
|
||||
#include "runtime/arguments.hpp"
|
||||
#include "runtime/deoptimization.hpp"
|
||||
#include "runtime/frame.inline.hpp"
|
||||
@@ -49,6 +51,7 @@
|
||||
#include "runtime/threadSMR.inline.hpp"
|
||||
#include "runtime/vmOperations.hpp"
|
||||
#include "services/threadService.hpp"
|
||||
#include "javaCalls.hpp"
|
||||
|
||||
#define VM_OP_NAME_INITIALIZE(name) #name,
|
||||
|
||||
@@ -158,6 +161,37 @@ void VM_ZombieAll::doit() {
|
||||
|
||||
#endif // !PRODUCT
|
||||
|
||||
|
||||
// Prints out additional information supplied by the application
|
||||
// through the use of JBR API. The data in the form of a String
|
||||
// are obtained from Throwable.$$jb$getAdditionalInfoForJstack()
|
||||
// and, not not null, are included into the output.
|
||||
void VM_PrintThreads::print_additional_info() {
|
||||
JavaThread *THREAD = JavaThread::current();
|
||||
HandleMark hm(THREAD);
|
||||
ResourceMark rm;
|
||||
|
||||
InstanceKlass *klass = vmClasses::Throwable_klass();
|
||||
if (klass != NULL) {
|
||||
TempNewSymbol method_name = SymbolTable::new_symbol("$$jb$getAdditionalInfoForJstack");
|
||||
Symbol *signature = vmSymbols::void_string_signature();
|
||||
Method *method = klass->find_method(method_name, signature);
|
||||
if (method != NULL) {
|
||||
JavaValue result(T_OBJECT);
|
||||
JavaCalls::call_static(&result, klass,
|
||||
method_name, signature, THREAD);
|
||||
oop dump_oop = result.get_oop();
|
||||
if (dump_oop != NULL) {
|
||||
// convert Java String to utf8 string
|
||||
char *s = java_lang_String::as_utf8_string(dump_oop);
|
||||
_out->cr();
|
||||
_out->print_raw_cr(s);
|
||||
_out->cr();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool VM_PrintThreads::doit_prologue() {
|
||||
// Get Heap_lock if concurrent locks will be dumped
|
||||
if (_print_concurrent_locks) {
|
||||
@@ -178,6 +212,13 @@ void VM_PrintThreads::doit_epilogue() {
|
||||
// Release Heap_lock
|
||||
Heap_lock->unlock();
|
||||
}
|
||||
|
||||
// We should be on the "signal handler" thread, which is a JavaThread
|
||||
if (Thread::current()->is_Java_thread()) {
|
||||
// .. but best play it safe as we're going to need to make
|
||||
// Java calls on the current thread.
|
||||
print_additional_info();
|
||||
}
|
||||
}
|
||||
|
||||
void VM_PrintMetadata::doit() {
|
||||
|
||||
@@ -154,6 +154,9 @@ class VM_PrintThreads: public VM_Operation {
|
||||
void doit();
|
||||
bool doit_prologue();
|
||||
void doit_epilogue();
|
||||
|
||||
private:
|
||||
void print_additional_info();
|
||||
};
|
||||
|
||||
class VM_PrintMetadata : public VM_Operation {
|
||||
|
||||
@@ -36,6 +36,8 @@ public class JBRApiModule {
|
||||
static {
|
||||
JBRApi.registerModule(MethodHandles.lookup(), JBRApiModule.class.getModule()::addExports)
|
||||
.service("com.jetbrains.JBR$ServiceApi")
|
||||
.withStatic("getService", "getService", "com.jetbrains.internal.JBRApi");
|
||||
.withStatic("getService", "getService", "com.jetbrains.internal.JBRApi")
|
||||
.service("com.jetbrains.Jstack")
|
||||
.withStatic("includeInfoFrom", "$$jb$additionalInfoForJstack", "java.lang.Throwable");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1130,4 +1130,20 @@ public class Throwable implements Serializable {
|
||||
else
|
||||
return suppressedExceptions.toArray(EMPTY_THROWABLE_ARRAY);
|
||||
}
|
||||
|
||||
private static volatile java.util.function.Supplier<String> $$jb$additionalInfoSupplier = null;
|
||||
|
||||
// JBR API internals
|
||||
private static void $$jb$additionalInfoForJstack(java.util.function.Supplier<String> supplier) {
|
||||
$$jb$additionalInfoSupplier = supplier;
|
||||
}
|
||||
|
||||
// NB: this is invoked from the VM
|
||||
private static String $$jb$getAdditionalInfoForJstack() {
|
||||
final java.util.function.Supplier<String> supplier = $$jb$additionalInfoSupplier;
|
||||
if (supplier != null) {
|
||||
return supplier.get();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,13 +160,19 @@ public final class UnixDomainSocketAddress extends SocketAddress {
|
||||
* @throws NullPointerException if path is {@code null}
|
||||
*/
|
||||
public static UnixDomainSocketAddress of(Path path) {
|
||||
FileSystem fs = path.getFileSystem();
|
||||
if (fs != FileSystems.getDefault()) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
if (fs.getClass().getModule() != Object.class.getModule()) {
|
||||
throw new IllegalArgumentException();
|
||||
final FileSystem fs = path.getFileSystem();
|
||||
final FileSystem defaultFS = sun.nio.fs.DefaultFileSystemProvider.theFileSystem();
|
||||
if (fs != defaultFS || fs.getClass().getModule() != Object.class.getModule()) {
|
||||
try {
|
||||
// Check if we'll be able to create a socket from this Path later on by
|
||||
// testing for the presence of a method identical to
|
||||
// AbstractFileSystemProvider.getSunPathForSocketFile()
|
||||
fs.provider().getClass().getMethod("getSunPathForSocketFile", Path.class);
|
||||
} catch (NoSuchMethodException | SecurityException e) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
return new UnixDomainSocketAddress(path);
|
||||
}
|
||||
|
||||
|
||||
@@ -99,8 +99,22 @@ class UnixDomainSockets {
|
||||
}
|
||||
|
||||
static byte[] getPathBytes(Path path) {
|
||||
FileSystemProvider provider = FileSystems.getDefault().provider();
|
||||
return ((AbstractFileSystemProvider) provider).getSunPathForSocketFile(path);
|
||||
java.nio.file.FileSystem fs = path.getFileSystem();
|
||||
FileSystemProvider provider = fs.provider();
|
||||
if (fs == sun.nio.fs.DefaultFileSystemProvider.theFileSystem()) {
|
||||
return ((AbstractFileSystemProvider) provider).getSunPathForSocketFile(path);
|
||||
} else {
|
||||
try {
|
||||
java.lang.reflect.Method method = provider.getClass().getMethod("getSunPathForSocketFile", Path.class);
|
||||
Object result = method.invoke(provider, path);
|
||||
return (byte[]) result;
|
||||
} catch (NoSuchMethodException | SecurityException e) {
|
||||
// This should've been verified when UnixDomainSocketAddress was created
|
||||
throw new Error("Can't find getSunPathForSocketFile(Path) in the non-default file system provider " + provider.getClass());
|
||||
} catch (java.lang.reflect.InvocationTargetException | IllegalAccessException e) {
|
||||
throw new RuntimeException("Can't invoke getSunPathForSocketFile(Path) from a non-default file system provider", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static FileDescriptor socket() throws IOException {
|
||||
@@ -136,13 +150,11 @@ class UnixDomainSockets {
|
||||
int rnd = random.nextInt(Integer.MAX_VALUE);
|
||||
try {
|
||||
final Path path = Path.of(dir, "socket_" + rnd);
|
||||
if (path.getFileSystem().provider() != sun.nio.fs.DefaultFileSystemProvider.instance()) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Unix Domain Sockets not supported on non-default file system");
|
||||
}
|
||||
return UnixDomainSocketAddress.of(path);
|
||||
} catch (InvalidPathException e) {
|
||||
throw new BindException("Invalid temporary directory");
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new UnsupportedOperationException("Unix Domain Sockets not supported on non-default file system without method getSunPathForSocketFile(Path)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,6 @@ BOOL isDisplaySyncEnabled() {
|
||||
self.framebufferOnly = YES;
|
||||
self.nextDrawableCount = 0;
|
||||
self.opaque = YES;
|
||||
self.presentsWithTransaction = YES;
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -133,6 +132,7 @@ BOOL isDisplaySyncEnabled() {
|
||||
destinationOrigin:MTLOriginMake(0, 0, 0)];
|
||||
[blitEncoder endEncoding];
|
||||
|
||||
[commandBuf presentDrawable:mtlDrawable];
|
||||
__block MTLLayer* layer = self;
|
||||
[layer retain];
|
||||
[commandBuf addCompletedHandler:^(id <MTLCommandBuffer> commandBuf) {
|
||||
@@ -141,8 +141,6 @@ BOOL isDisplaySyncEnabled() {
|
||||
}];
|
||||
|
||||
[commandBuf commit];
|
||||
[commandBuf waitUntilScheduled];
|
||||
[mtlDrawable present];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,9 @@ abstract class XDecoratedPeer extends XWindowPeer {
|
||||
// reparented - indicates that WM has adopted the top-level.
|
||||
boolean configure_seen;
|
||||
boolean insets_corrected;
|
||||
// Set to true after reconfigureContentWindow is called for the first time.
|
||||
// Before this, content window may not be in sync with insets.
|
||||
private boolean content_reconfigured;
|
||||
|
||||
XIconWindow iconWindow;
|
||||
volatile WindowDimensions dimensions;
|
||||
@@ -736,6 +739,7 @@ abstract class XDecoratedPeer extends XWindowPeer {
|
||||
return;
|
||||
}
|
||||
content.setContentBounds(dims);
|
||||
content_reconfigured = true;
|
||||
}
|
||||
|
||||
private XEvent pendingConfigureEvent;
|
||||
@@ -875,6 +879,14 @@ abstract class XDecoratedPeer extends XWindowPeer {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
WindowLocation queryXLocation() {
|
||||
XContentWindow c = content;
|
||||
boolean client = c == null || !content_reconfigured;
|
||||
return new WindowLocation(XlibUtil.translateCoordinates(client ? window : c.getWindow(),
|
||||
XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber()), 0, 0), client);
|
||||
}
|
||||
|
||||
private void checkShellRectSize(Rectangle shellRect) {
|
||||
shellRect.width = Math.max(MIN_SIZE, shellRect.width);
|
||||
shellRect.height = Math.max(MIN_SIZE, shellRect.height);
|
||||
|
||||
@@ -1143,12 +1143,8 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
|
||||
* insets are calculated using _NET_WORKAREA property of the root window.
|
||||
* <p>
|
||||
* Note that _NET_WORKAREA is a rectangular area and it does not work
|
||||
* well in the Xinerama mode.
|
||||
* <p>
|
||||
* We will trust the part of this rectangular area only if it starts at the
|
||||
* requested graphics configuration. Below is an example when the
|
||||
* _NET_WORKAREA intersects with the requested graphics configuration but
|
||||
* produces wrong result.
|
||||
* well in the Xinerama mode, so we assume that only 0th screen has insets.
|
||||
* Below is an example when _NET_WORKAREA produces wrong result.
|
||||
*
|
||||
* //<-x1,y1///////
|
||||
* // // ////////////////
|
||||
@@ -1166,20 +1162,25 @@ public final class XToolkit extends UNIXToolkit implements Runnable {
|
||||
if (np == null || !(gd instanceof X11GraphicsDevice) || !np.active()) {
|
||||
return super.getScreenInsets(gc);
|
||||
}
|
||||
X11GraphicsDevice x11gd = (X11GraphicsDevice) gd;
|
||||
int screenNum = x11gd.getScreen();
|
||||
if (localEnv.runningXinerama() && screenNum != 0) {
|
||||
// We cannot estimate insets for non-default screen,
|
||||
// there are often none.
|
||||
return new Insets(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
XToolkit.awtLock();
|
||||
try {
|
||||
X11GraphicsDevice x11gd = (X11GraphicsDevice) gd;
|
||||
long root = XlibUtil.getRootWindow(x11gd.getScreen());
|
||||
Rectangle workArea = getWorkArea(root);
|
||||
Rectangle workArea = getWorkArea(XlibUtil.getRootWindow(screenNum));
|
||||
Rectangle screen = gc.getBounds();
|
||||
if (workArea != null) {
|
||||
workArea.x = x11gd.scaleDownX(workArea.x);
|
||||
workArea.y = x11gd.scaleDownY(workArea.y);
|
||||
workArea.width = x11gd.scaleDown(workArea.width);
|
||||
workArea.height = x11gd.scaleDown(workArea.height);
|
||||
if (screen.contains(workArea.getLocation())) {
|
||||
workArea = workArea.intersection(screen);
|
||||
workArea = workArea.intersection(screen);
|
||||
if (!workArea.isEmpty()) {
|
||||
int top = workArea.y - screen.y;
|
||||
int left = workArea.x - screen.x;
|
||||
int bottom = screen.height - workArea.height - top;
|
||||
|
||||
@@ -774,7 +774,7 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
|
||||
class WindowLocation {
|
||||
private final Point location; // Device space
|
||||
private final boolean client;
|
||||
private WindowLocation(Point location, boolean client) {
|
||||
WindowLocation(Point location, boolean client) {
|
||||
this.location = location;
|
||||
this.client = client;
|
||||
}
|
||||
@@ -803,6 +803,11 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
|
||||
}
|
||||
}
|
||||
|
||||
WindowLocation queryXLocation() {
|
||||
return new WindowLocation(XlibUtil.translateCoordinates(getContentWindow(),
|
||||
XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber()), 0, 0), false);
|
||||
}
|
||||
|
||||
WindowLocation getNewLocation(XConfigureEvent xe) {
|
||||
int runningWM = XWM.getWMID();
|
||||
if (xe.get_send_event() ||
|
||||
@@ -825,13 +830,11 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
|
||||
case XWM.UNITY_COMPIZ_WM:
|
||||
case XWM.AWESOME_WM:
|
||||
{
|
||||
Point xlocation = XlibUtil.translateCoordinates(getContentWindow(), XlibWrapper
|
||||
.RootWindow(XToolkit.getDisplay(),
|
||||
getScreenNumber()), 0, 0);
|
||||
WindowLocation xlocation = queryXLocation();
|
||||
if (log.isLoggable(PlatformLogger.Level.FINE)) {
|
||||
log.fine("New X location: {0}", xlocation);
|
||||
log.fine("New X location: {0} ({1})", xlocation.location, xlocation.client ? "client" : "bounds");
|
||||
}
|
||||
return new WindowLocation(xlocation, false);
|
||||
return xlocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,6 +143,32 @@ static void* get_schema_value(char *name, char *key) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// When monitor framebuffer scaling enabled, compositor scales down monitor resolutions according to their scales,
|
||||
// so that we're working in logical, not device pixels, just like in macOS. This approach is used for implementing
|
||||
// fractional scaling, so basically this function tells you whether fractional scaling is enabled or not.
|
||||
int isMonitorFramebufferScalingEnabled() {
|
||||
int result = 0;
|
||||
void* features = get_schema_value("org.gnome.mutter", "experimental-features");
|
||||
if (features) {
|
||||
if (fp_g_variant_is_of_type(features, "as")) {
|
||||
int numFeatures = fp_g_variant_n_children(features);
|
||||
for (int i = 0; i < numFeatures; i++) {
|
||||
void* feature = fp_g_variant_get_child_value(features, i);
|
||||
if (feature) {
|
||||
char* name = fp_g_variant_get_string(feature, NULL);
|
||||
if (name && strcmp(name, "scale-monitor-framebuffer") == 0) {
|
||||
result = 1;
|
||||
}
|
||||
fp_g_variant_unref(feature);
|
||||
if (result) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fp_g_variant_unref(features);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static double getDesktopScale(char *output_name) {
|
||||
double result = -1;
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
double getNativeScaleFactor(char *output_name, double default_value);
|
||||
double getScaleEnvVar(const char* var_name, double default_value);
|
||||
int isMonitorFramebufferScalingEnabled();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -802,24 +802,28 @@ Java_sun_awt_X11GraphicsEnvironment_updateWaylandMonitorScaling(JNIEnv *env, jcl
|
||||
if (!usingXinerama || !wlLibHandle) return;
|
||||
|
||||
struct UpdateWaylandMonitorsData monData;
|
||||
monData.xinInfo = (*XineramaQueryScreens)(awt_display, &monData.xinScreens);
|
||||
if (monData.xinInfo == NULL) return;
|
||||
wl_display* display = wl_display_connect(NULL);
|
||||
if (display == NULL) return;
|
||||
monData.waylandMonitorScales = calloc(monData.xinScreens, sizeof(int32_t));
|
||||
monData.currentWaylandMonitor = -1;
|
||||
monData.currentWaylandScale = 1;
|
||||
monData.waylandMonitorScales = NULL;
|
||||
if (!isMonitorFramebufferScalingEnabled()) {
|
||||
monData.xinInfo = (*XineramaQueryScreens)(awt_display, &monData.xinScreens);
|
||||
if (monData.xinInfo == NULL) return;
|
||||
wl_display* display = wl_display_connect(NULL);
|
||||
if (display == NULL) return;
|
||||
monData.waylandMonitorScales = calloc(monData.xinScreens, sizeof(int32_t));
|
||||
|
||||
wl_registry* registry = wl_proxy_marshal_constructor(display, 1, wl_registry_interface, NULL); // wl_display_get_registry
|
||||
wl_proxy_add_listener(registry, (void (**)(void)) &wlRegistryListener, &monData); // wl_registry_add_listener
|
||||
wl_display_roundtrip(display); // Get globals (wl_outputs)
|
||||
wl_display_roundtrip(display); // Get outputs info
|
||||
wl_registry* registry = wl_proxy_marshal_constructor(display, 1, wl_registry_interface, NULL); // wl_display_get_registry
|
||||
wl_proxy_add_listener(registry, (void (**)(void)) &wlRegistryListener, &monData); // wl_registry_add_listener
|
||||
wl_display_roundtrip(display); // Get globals (wl_outputs)
|
||||
wl_display_roundtrip(display); // Get outputs info
|
||||
|
||||
XFree(monData.xinInfo);
|
||||
wl_display_disconnect(display);
|
||||
XFree(monData.xinInfo);
|
||||
}
|
||||
|
||||
int32_t* oldScales = waylandMonitorScales;
|
||||
waylandMonitorScales = monData.waylandMonitorScales;
|
||||
free(oldScales);
|
||||
|
||||
wl_display_disconnect(display);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
46
src/jetbrains.api/src/com/jetbrains/Jstack.java
Normal file
46
src/jetbrains.api/src/com/jetbrains/Jstack.java
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2023 JetBrains s.r.o.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code 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 General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.jetbrains;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface Jstack {
|
||||
/**
|
||||
* Specifies a supplier of additional information to be included into
|
||||
* the output of {@code jstack}. The String supplied will be included
|
||||
* as-is with no header surrounded only with line breaks.
|
||||
*
|
||||
* {@code infoSupplier} will be invoked on an unspecified thread that
|
||||
* must not be left blocked for a long time.
|
||||
*
|
||||
* Only one supplier is allowed, so subsequent calls to
|
||||
* {@code includeInfoFrom} will overwrite the previously specified supplier.
|
||||
*
|
||||
* @param infoSupplier a supplier of {@code String} values to be
|
||||
* included into jstack's output. If {@code null},
|
||||
* then the previously registered supplier is removed
|
||||
* (if any) and no extra info will be included.
|
||||
*/
|
||||
void includeInfoFrom(Supplier<String> infoSupplier);
|
||||
}
|
||||
@@ -6,9 +6,9 @@
|
||||
# 2. When only new API is added, or some existing API was @Deprecated - increment MINOR, reset PATCH to 0
|
||||
# 3. For major backwards incompatible API changes - increment MAJOR, reset MINOR and PATCH to 0
|
||||
|
||||
VERSION = 0.0.11
|
||||
VERSION = 0.0.12
|
||||
|
||||
# Hash is used to track changes to jetbrains.api, so you would not forget to update version when needed.
|
||||
# When you make any changes, "make jbr-api" will fail and ask you to update hash and version number here.
|
||||
|
||||
HASH = 8FEFE261B473A778A5BC77FBC83D32
|
||||
HASH = 2C7C5F48509A9C542CBE202930B871
|
||||
|
||||
59
test/jdk/jb/java/api/frontend/JstackTest.java
Normal file
59
test/jdk/jb/java/api/frontend/JstackTest.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2023 JetBrains s.r.o.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Verifies that jstack includes whatever the supplier
|
||||
* provided to Jstack.includeInfoFrom() returns.
|
||||
* @library /test/lib
|
||||
* @run shell build.sh
|
||||
* @run main JstackTest
|
||||
*/
|
||||
|
||||
import com.jetbrains.JBR;
|
||||
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import jdk.test.lib.JDKToolFinder;
|
||||
import jdk.test.lib.Platform;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class JstackTest {
|
||||
final static String MAGIC_STRING = "Additional info:\nthis appears in jstack's output";
|
||||
|
||||
public static void main(String[] args) {
|
||||
JBR.getJstack().includeInfoFrom( () -> MAGIC_STRING );
|
||||
long pid = ProcessHandle.current().pid();
|
||||
final OutputAnalyzer jstackOutput = runJstack(pid);
|
||||
jstackOutput
|
||||
.shouldHaveExitValue(0)
|
||||
.shouldContain(MAGIC_STRING);
|
||||
}
|
||||
|
||||
static OutputAnalyzer runJstack(long pid) {
|
||||
try {
|
||||
final String JSTACK = JDKToolFinder.getTestJDKTool("jstack");
|
||||
final ProcessBuilder pb = new ProcessBuilder(JSTACK, String.valueOf(pid));
|
||||
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||
output.outputTo(System.out);
|
||||
output.shouldHaveExitValue(0);
|
||||
return output;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Launching jstack failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
481
test/jdk/jb/java/nio/file/spi/TestProvider.java
Normal file
481
test/jdk/jb/java/nio/file/spi/TestProvider.java
Normal file
@@ -0,0 +1,481 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code 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 General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.nio.file.attribute.FileAttribute;
|
||||
import java.nio.file.attribute.FileAttributeView;
|
||||
import java.nio.file.attribute.UserPrincipalLookupService;
|
||||
import java.nio.file.spi.FileSystemProvider;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.SeekableByteChannel;
|
||||
import java.net.URI;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestProvider extends FileSystemProvider {
|
||||
|
||||
private final FileSystemProvider defaultProvider;
|
||||
private final TestFileSystem theFileSystem;
|
||||
|
||||
public TestProvider(FileSystemProvider defaultProvider) {
|
||||
this.defaultProvider = defaultProvider;
|
||||
FileSystem fs = defaultProvider.getFileSystem(URI.create("file:/"));
|
||||
this.theFileSystem = new TestFileSystem(fs, this);
|
||||
}
|
||||
|
||||
FileSystemProvider defaultProvider() {
|
||||
return defaultProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScheme() {
|
||||
return "file";
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileSystem newFileSystem(URI uri, Map<String,?> env) throws IOException {
|
||||
return defaultProvider.newFileSystem(uri, env);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileSystem getFileSystem(URI uri) {
|
||||
return theFileSystem;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getPath(URI uri) {
|
||||
Path path = defaultProvider.getPath(uri);
|
||||
return theFileSystem.wrap(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAttribute(Path file, String attribute, Object value,
|
||||
LinkOption... options)
|
||||
throws IOException
|
||||
{
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String,Object> readAttributes(Path file, String attributes,
|
||||
LinkOption... options)
|
||||
throws IOException
|
||||
{
|
||||
Path delegate = theFileSystem.unwrap(file);
|
||||
return defaultProvider.readAttributes(delegate, attributes, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <A extends BasicFileAttributes> A readAttributes(Path file,
|
||||
Class<A> type,
|
||||
LinkOption... options)
|
||||
throws IOException
|
||||
{
|
||||
Path delegate = theFileSystem.unwrap(file);
|
||||
return defaultProvider.readAttributes(delegate, type, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V extends FileAttributeView> V getFileAttributeView(Path file,
|
||||
Class<V> type,
|
||||
LinkOption... options)
|
||||
{
|
||||
Path delegate = theFileSystem.unwrap(file);
|
||||
return defaultProvider.getFileAttributeView(delegate, type, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Path file) throws IOException {
|
||||
Path delegate = theFileSystem.unwrap(file);
|
||||
defaultProvider.delete(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs)
|
||||
throws IOException
|
||||
{
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createLink(Path link, Path existing) throws IOException {
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path readSymbolicLink(Path link) throws IOException {
|
||||
Path delegate = theFileSystem.unwrap(link);
|
||||
Path target = defaultProvider.readSymbolicLink(delegate);
|
||||
return theFileSystem.wrap(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy(Path source, Path target, CopyOption... options)
|
||||
throws IOException
|
||||
{
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(Path source, Path target, CopyOption... options)
|
||||
throws IOException
|
||||
{
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirectoryStream<Path> newDirectoryStream(Path dir,
|
||||
DirectoryStream.Filter<? super Path> filter)
|
||||
throws IOException
|
||||
{
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createDirectory(Path dir, FileAttribute<?>... attrs)
|
||||
throws IOException
|
||||
{
|
||||
Path delegate = theFileSystem.unwrap(dir);
|
||||
defaultProvider.createDirectory(delegate, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SeekableByteChannel newByteChannel(Path file,
|
||||
Set<? extends OpenOption> options,
|
||||
FileAttribute<?>... attrs)
|
||||
throws IOException
|
||||
{
|
||||
Path delegate = theFileSystem.unwrap(file);
|
||||
return defaultProvider.newByteChannel(delegate, options, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileChannel newFileChannel(Path file,
|
||||
Set<? extends OpenOption> options,
|
||||
FileAttribute<?>... attrs)
|
||||
throws IOException
|
||||
{
|
||||
Path delegate = theFileSystem.unwrap(file);
|
||||
return defaultProvider.newFileChannel(delegate, options, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHidden(Path file) throws IOException {
|
||||
throw new ReadOnlyFileSystemException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileStore getFileStore(Path file) throws IOException {
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSameFile(Path file, Path other) throws IOException {
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkAccess(Path file, AccessMode... modes)
|
||||
throws IOException
|
||||
{
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
static class TestFileSystem extends FileSystem {
|
||||
private final FileSystem delegate;
|
||||
private final TestProvider provider;
|
||||
|
||||
TestFileSystem(FileSystem delegate, TestProvider provider) {
|
||||
this.delegate = delegate;
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
Path wrap(Path path) {
|
||||
return (path != null) ? new TestPath(this, path) : null;
|
||||
}
|
||||
|
||||
Path unwrap(Path wrapper) {
|
||||
if (wrapper == null)
|
||||
throw new NullPointerException();
|
||||
if (!(wrapper instanceof TestPath))
|
||||
throw new ProviderMismatchException();
|
||||
return ((TestPath)wrapper).unwrap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileSystemProvider provider() {
|
||||
return provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSeparator() {
|
||||
return delegate.getSeparator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Path> getRootDirectories() {
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<FileStore> getFileStores() {
|
||||
throw new RuntimeException("not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> supportedFileAttributeViews() {
|
||||
return delegate.supportedFileAttributeViews();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getPath(String first, String... more) {
|
||||
Path path = delegate.getPath(first, more);
|
||||
return wrap(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PathMatcher getPathMatcher(String syntaxAndPattern) {
|
||||
return delegate.getPathMatcher(syntaxAndPattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserPrincipalLookupService getUserPrincipalLookupService() {
|
||||
return delegate.getUserPrincipalLookupService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WatchService newWatchService() throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
static class TestPath implements Path {
|
||||
private final TestFileSystem fs;
|
||||
private final Path delegate;
|
||||
|
||||
TestPath(TestFileSystem fs, Path delegate) {
|
||||
this.fs = fs;
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
Path unwrap() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileSystem getFileSystem() {
|
||||
return fs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbsolute() {
|
||||
return delegate.isAbsolute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getRoot() {
|
||||
return fs.wrap(delegate.getRoot());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getParent() {
|
||||
return fs.wrap(delegate.getParent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getNameCount() {
|
||||
return delegate.getNameCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getFileName() {
|
||||
return fs.wrap(delegate.getFileName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getName(int index) {
|
||||
return fs.wrap(delegate.getName(index));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path subpath(int beginIndex, int endIndex) {
|
||||
return fs.wrap(delegate.subpath(beginIndex, endIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startsWith(Path other) {
|
||||
return delegate.startsWith(fs.unwrap(other));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startsWith(String other) {
|
||||
return delegate.startsWith(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean endsWith(Path other) {
|
||||
return delegate.endsWith(fs.unwrap(other));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean endsWith(String other) {
|
||||
return delegate.endsWith(other);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path normalize() {
|
||||
return fs.wrap(delegate.normalize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path resolve(Path other) {
|
||||
return fs.wrap(delegate.resolve(fs.unwrap(other)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path resolve(String other) {
|
||||
return fs.wrap(delegate.resolve(other));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path resolveSibling(Path other) {
|
||||
return fs.wrap(delegate.resolveSibling(fs.unwrap(other)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path resolveSibling(String other) {
|
||||
return fs.wrap(delegate.resolveSibling(other));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path relativize(Path other) {
|
||||
return fs.wrap(delegate.relativize(fs.unwrap(other)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (!(other instanceof TestPath))
|
||||
return false;
|
||||
return delegate.equals(fs.unwrap((TestPath) other));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return delegate.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return delegate.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI toUri() {
|
||||
String ssp = delegate.toUri().getSchemeSpecificPart();
|
||||
return URI.create(fs.provider().getScheme() + ":" + ssp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path toAbsolutePath() {
|
||||
return fs.wrap(delegate.toAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path toRealPath(LinkOption... options) throws IOException {
|
||||
return fs.wrap(delegate.toRealPath(options));
|
||||
}
|
||||
|
||||
@Override
|
||||
public File toFile() {
|
||||
return new File(toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Path> iterator() {
|
||||
final Iterator<Path> itr = delegate.iterator();
|
||||
return new Iterator<Path>() {
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return itr.hasNext();
|
||||
}
|
||||
@Override
|
||||
public Path next() {
|
||||
return fs.wrap(itr.next());
|
||||
}
|
||||
@Override
|
||||
public void remove() {
|
||||
itr.remove();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Path other) {
|
||||
return delegate.compareTo(fs.unwrap(other));
|
||||
}
|
||||
|
||||
@Override
|
||||
public WatchKey register(WatchService watcher,
|
||||
WatchEvent.Kind<?>[] events,
|
||||
WatchEvent.Modifier... modifiers)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WatchKey register(WatchService watcher,
|
||||
WatchEvent.Kind<?>... events)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
private static final byte[] EMPTY_PATH = new byte[0];
|
||||
|
||||
public byte[] getSunPathForSocketFile(Path path) {
|
||||
if (path.getNameCount() == 0) {
|
||||
return EMPTY_PATH;
|
||||
}
|
||||
return path.toString().getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2023, JetBrains s.r.o.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code 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 General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @summary Verifies that Unix domain sockets work with a non-default
|
||||
* file system provider that implements
|
||||
* @library /test/lib
|
||||
* @build TestProvider
|
||||
* @run main/othervm -Djava.nio.file.spi.DefaultFileSystemProvider=TestProvider UnixSocketWithCustomProvider
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.StandardProtocolFamily;
|
||||
import java.net.UnixDomainSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.spi.FileSystemProvider;
|
||||
|
||||
public class UnixSocketWithCustomProvider {
|
||||
public static void main(String[] args) {
|
||||
FileSystemProvider provider = FileSystems.getDefault().provider();
|
||||
if (!provider.getClass().getName().equals("TestProvider")) {
|
||||
throw new Error("Test must be run with non-default file system");
|
||||
}
|
||||
|
||||
Path socketPath = Path.of("socket");
|
||||
UnixDomainSocketAddress socketAddress = UnixDomainSocketAddress.of(socketPath);
|
||||
try (ServerSocketChannel serverCh = ServerSocketChannel.open(StandardProtocolFamily.UNIX)) {
|
||||
serverCh.bind(socketAddress);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
Files.deleteIfExists(socketPath);
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
135
test/jdk/jb/javax/swing/JTextArea/TypingLatencyTest.java
Normal file
135
test/jdk/jb/javax/swing/JTextArea/TypingLatencyTest.java
Normal file
@@ -0,0 +1,135 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.PriorityQueue;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @summary Measure typing latency in JTextArea with various conditions (count of already added symbols)
|
||||
* The test adds initial size of text in the JTextArea by specified <code>jtreg.test.initialSize</code> property.
|
||||
* After that robot types predefined amount of english symbols in the beginning of the text in JTextArea.
|
||||
* Amount of symbols is defined in <code>jtreg.test.sampleSize</code> property.
|
||||
* @run main/othervm -Djtreg.test.initialSize=0 -Djtreg.test.sampleSize=100 TypingLatencyTest
|
||||
* @run main/othervm -Djtreg.test.initialSize=1000 -Djtreg.test.sampleSize=50 TypingLatencyTest
|
||||
* @run main/othervm -Djtreg.test.initialSize=5000 -Djtreg.test.sampleSize=50 TypingLatencyTest
|
||||
* @run main/othervm -Djtreg.test.initialSize=10000 -Djtreg.test.sampleSize=50 TypingLatencyTest
|
||||
* @run main/othervm -Djtreg.test.initialSize=30000 -Djtreg.test.sampleSize=50 TypingLatencyTest
|
||||
*/
|
||||
public class TypingLatencyTest {
|
||||
|
||||
private static final DecimalFormat df = new DecimalFormat("0.00");
|
||||
|
||||
private static JFrame window;
|
||||
private static JTextArea textArea;
|
||||
private static Robot robot;
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
int initialSize = 0;
|
||||
String initialSizeValue = System.getProperty("jtreg.test.initialSize");
|
||||
if (initialSizeValue != null && !initialSizeValue.isBlank()) {
|
||||
initialSize = Integer.parseInt(initialSizeValue);
|
||||
}
|
||||
|
||||
int sampleSize = 0;
|
||||
String sampleSizeValue = System.getProperty("jtreg.test.sampleSize");
|
||||
if (sampleSizeValue != null && !sampleSizeValue.isBlank()) {
|
||||
sampleSize = Integer.parseInt(sampleSizeValue);
|
||||
}
|
||||
|
||||
System.out.println("Run test with: initialSize = " + initialSize + " sampleSize = " + sampleSize);
|
||||
|
||||
try {
|
||||
robot = new Robot();
|
||||
SwingUtilities.invokeAndWait(TypingLatencyTest::createUI);
|
||||
robot.waitForIdle();
|
||||
boolean passed = typeAndMeasureLatency(initialSize, sampleSize);
|
||||
if (!passed) {
|
||||
throw new RuntimeException("TEST FAILED: Typing latency is too high.");
|
||||
}
|
||||
} finally {
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
if (window != null) {
|
||||
window.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void createUI() {
|
||||
window = new JFrame();
|
||||
window.setBounds(0, 0, 800, 600);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
textArea = new JTextArea();
|
||||
textArea.setColumns(60);
|
||||
textArea.setLineWrap(true);
|
||||
textArea.setRows(30);
|
||||
|
||||
panel.add(textArea);
|
||||
|
||||
window.setContentPane(panel);
|
||||
window.setVisible(true);
|
||||
}
|
||||
|
||||
private static boolean typeAndMeasureLatency(int initialTextSize, int sampleSize) {
|
||||
window.requestFocus();
|
||||
textArea.requestFocus();
|
||||
robot.waitForIdle();
|
||||
|
||||
textArea.append(generateText(initialTextSize));
|
||||
|
||||
long before, after, diff;
|
||||
int code;
|
||||
|
||||
long min = Long.MAX_VALUE;
|
||||
long max = Long.MIN_VALUE;
|
||||
double average = 0;
|
||||
PriorityQueue<Long> small = new PriorityQueue<>(Collections.reverseOrder());
|
||||
PriorityQueue<Long> large = new PriorityQueue<>();
|
||||
boolean even = true;
|
||||
|
||||
for (int i = 0; i < sampleSize; i++) {
|
||||
code = KeyEvent.getExtendedKeyCodeForChar(97 + Math.round(25 * (float) Math.random()));
|
||||
|
||||
before = System.nanoTime();
|
||||
robot.keyPress(code);
|
||||
robot.keyRelease(code);
|
||||
robot.waitForIdle();
|
||||
after = System.nanoTime();
|
||||
diff = after - before;
|
||||
|
||||
if (even) {
|
||||
large.offer(diff);
|
||||
small.offer(large.poll());
|
||||
} else {
|
||||
small.offer(diff);
|
||||
large.offer(small.poll());
|
||||
}
|
||||
even = !even;
|
||||
min = Math.min(min, diff);
|
||||
max = Math.max(max, diff);
|
||||
average = ((average * i) + diff) / (i + 1);
|
||||
}
|
||||
|
||||
double median = even ? (small.peek() + large.peek()) / 2.0 : small.peek();
|
||||
|
||||
System.out.println("Symbols added: " + sampleSize);
|
||||
System.out.println("min (ms): " + df.format((min / 1_000_000.0)));
|
||||
System.out.println("max (ms): " + df.format((max / 1_000_000.0)));
|
||||
System.out.println("average (ms): " + df.format((average / 1_000_000.0)));
|
||||
System.out.println("median (ms): " + df.format((median / 1_000_000.0)));
|
||||
|
||||
return median < 500_000_000;
|
||||
}
|
||||
|
||||
private static String generateText(int size) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < size; i++) {
|
||||
sb.append((char) (97 + Math.round(25 * (float) Math.random())));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1067,7 +1067,6 @@ java/awt/Frame/LayoutOnMaximizeTest/LayoutOnMaximizeTest.java JBR-4880 windows-a
|
||||
java/awt/Frame/MiscUndecorated/UndecoratedInitiallyIconified.java JBR-4880 windows-all
|
||||
java/awt/FullScreen/FullscreenWindowProps/FullscreenWindowProps.java JBR-4275,JBR-4880 linux-all,windows-all
|
||||
java/awt/FullScreen/SetFSWindow/FSFrame.java 8253184 windows-all
|
||||
java/awt/grab/EmbeddedFrameTest1/EmbeddedFrameTest1.java JBR-4880 windows-all
|
||||
java/awt/grab/GrabOnUnfocusableToplevel/GrabOnUnfocusableToplevel.java JBR-4880 windows-all
|
||||
java/awt/grab/MenuDragEvents/MenuDragEvents.java JBR-4880 windows-all
|
||||
java/awt/image/multiresolution/MenuMultiresolutionIconTest.java JBR-4880,8253184 windows-all
|
||||
|
||||
Reference in New Issue
Block a user