oracle / visualvm

VisualVM is an All-in-One Java Troubleshooting Tool
https://visualvm.github.io/
Other
2.78k stars 297 forks source link

Add the ability to choose UI Font Size. #575

Open vyalyh-oleg opened 3 weeks ago

vyalyh-oleg commented 3 weeks ago

On the HiDPI screens the visualvm starts with quite normal font size (thanks to GDK_SCALE=2 or QT_SCALE env variables). Also there is possibility to use -J-D property: -J-Dsun.java2d.uiScale=2.

But! These parameters touch the entire scaling including fonts, which was already normal. As a result -- we'll see the huge fonts on the normal UI elements, or tiny elements with normal fonts.

I know the complexity related to Java Swing (cause, i also java dev), but there is a workaround. Before showing the program's GUI, the font size can be set directly, and its value can be stored in config file or is get from -J-D property. This is can be made even more intellectual -- calculate the relative size (or coefficient) of the fonts based on the presence of GDK_SCALE or QT_SCALE environments.

But again, the simplest way for implementation -- is just to set the ui font globally on the start.

upd. I've read about the hack with --fontsize command, but it doesn't work neither with GDK_SCALE nor sun.java2d.uiScale variables.

thurka commented 2 weeks ago

--fontsize is not a hack. What exactly does not work?

vyalyh-oleg commented 2 weeks ago

Ok, not a hack, let me rephrase. It is a possibility to set base fontsize for swing.

What exactly does not work?

I've described it in the very beginning. In short:

As a result -- we'll see the huge fonts on the normal UI elements, or tiny elements with normal fonts.

The --fontsize does nothing, at least for now.

Here is the example: visualvm -J-Dsun.java2d.dpiaware=false -J-Dsun.java2d.uiScale=1 -J-Dswing.useSystemFontSettings=false -J-Dnetbeans.plaf.disable.ui.customizations=true --fontsize 20

For scale=1 image

For scale=2 (the screenshot is really huge, the browser just squeezed it) image

thurka commented 2 weeks ago

Thanks a lot for the update and screenshots. It would be great if you can attach VisualVM messages.log. This will help us understand your setup.

messages.log is available via Help | About | Logfile

vyalyh-oleg commented 2 weeks ago

Yes, sure. (sorry, didn't find how to make it foldable)

-------------------------------------------------------------------------------
>Log Session: Friday, June 14, 2024, 8:22:22 PM Eastern European Summer Time
>System Info: 
  Product Version         = VisualVM 2.1.7
  Operating System        = Linux version 5.15.0-107-generic running on amd64
  Java; VM; Vendor        = 21.0.2; OpenJDK 64-Bit Server VM 21.0.2+13-58; Oracle Corporation
  Runtime                 = OpenJDK Runtime Environment 21.0.2+13-58
  Java Home               = /opt/java/jdk-21.0.2+13-58-openjdk
  System Locale; Encoding = en_US (visualvm); UTF-8
  Home Directory          = /home/<user_name>
  Current Directory       = /home/<user_name>
  User Directory          = /home/<user_name>/.visualvm/2.1.7
  Cache Directory         = /home/<user_name>/.cache/visualvm/2.1.7
  Installation            = /opt/java/visualvm/visualvm
                            /opt/java/visualvm/platform
  Boot & Ext. Classpath   = 
  Application Classpath   = /opt/java/visualvm/platform/lib/boot.jar:/opt/java/visualvm/platform/lib/org-openide-modules.jar:/opt/java/visualvm/platform/lib/org-openide-util.jar:/opt/java/visualvm/platform/lib/org-openide-util-lookup.jar:/opt/java/visualvm/platform/lib/org-openide-util-ui.jar
  Startup Classpath       = /opt/java/visualvm/platform/core/core.jar:/opt/java/visualvm/platform/core/asm-9.2.jar:/opt/java/visualvm/platform/core/asm-tree-9.2.jar:/opt/java/visualvm/platform/core/asm-commons-9.2.jar:/opt/java/visualvm/platform/core/core-base.jar:/opt/java/visualvm/platform/core/org-netbeans-libs-asm.jar:/opt/java/visualvm/platform/core/org-openide-filesystems.jar:/opt/java/visualvm/visualvm/core/org-graalvm-visualvm-modules-startup.jar:/opt/java/visualvm/visualvm/core/locale/core_visualvm.jar
-------------------------------------------------------------------------------
INFO [org.netbeans.core.startup.NbEvents]: Turning on modules:
    org.openide.util.lookup [8.50 20230511-c4f2d87113]
    org.openide.util [9.24 20230511-c4f2d87113]
    org.openide.util.ui [9.24 20230511-c4f2d87113]
    org.openide.modules [7.64 20230511-c4f2d87113]
    org.netbeans.api.progress/1 [1.64 20230511-c4f2d87113]
    org.netbeans.api.annotations.common/1 [1.44 20230511-c4f2d87113]
    org.openide.filesystems [9.28 20230511-c4f2d87113]
    org.openide.awt [7.84 20230511-c4f2d87113]
    org.netbeans.swing.plaf [1.58 20230511-c4f2d87113]
    org.netbeans.api.progress.nb [1.64 20230511-c4f2d87113]
    org.openide.dialogs [7.61 20230511-c4f2d87113]
    org.openide.nodes [7.61 20230511-c4f2d87113]
    org.openide.windows [6.93 20230511-c4f2d87113]
    org.netbeans.swing.tabcontrol [1.72 20230511-c4f2d87113]
    org.netbeans.swing.outline [1.50 20230511-c4f2d87113]
    org.openide.explorer [6.78 20230511-c4f2d87113]
    org.netbeans.modules.editor.mimelookup/1 [1.56 20230511-c4f2d87113]
    org.openide.text [6.84 20230511-c4f2d87113]
    org.openide.actions [6.55 20230511-c4f2d87113]
    org.netbeans.modules.keyring [1.40 20230511-c4f2d87113]
    org.netbeans.api.intent [1.18 20230511-c4f2d87113]
    org.netbeans.api.io [1.19 20230511-c4f2d87113]
    org.openide.io [1.65 20230511-c4f2d87113]
    org.netbeans.libs.asm [5.19 20230511-c4f2d87113]
    org.netbeans.bootstrap/1 [2.94 20230511-c4f2d87113]
    org.netbeans.core.startup.base [1.78.0.1 1 20230511-c4f2d87113]
    org.netbeans.core.startup/1 [1.78.0.1 20230511-c4f2d87113]
    org.netbeans.modules.sampler [1.30 20230511-c4f2d87113]
    org.netbeans.api.scripting [1.13 20230511-c4f2d87113]
    org.netbeans.modules.queries/1 [1.59 20230511-c4f2d87113]
    org.netbeans.api.templates [1.24 20230511-c4f2d87113]
    org.openide.filesystems.nb [9.26 20230511-c4f2d87113]
    org.openide.loaders [7.86 20230511-c4f2d87113]
    org.netbeans.core/2 [3.67 20230511-c4f2d87113]
    org.netbeans.spi.quicksearch [1.43 20230511-c4f2d87113]
    org.netbeans.modules.options.api/1 [1.61 20230511-c4f2d87113]
    org.graalvm.visualvm.lib.charts/2 [2.1 230906]
    org.graalvm.visualvm.lib.jfluid/2 [2.15 230906]
    org.graalvm.visualvm.lib.common/2 [2.8 230906]
    org.graalvm.visualvm.lib.profiler.api/2 [2.2 230906]
    org.graalvm.visualvm.lib.ui/2 [2.4 230906]
    org.graalvm.visualvm.uisupport/2 [2.1 230906]
    org.netbeans.modules.sendopts/2 [2.52 20230511-c4f2d87113]
    org.graalvm.visualvm.core/2 [2.4 230906]
    org.graalvm.visualvm.modules.tracer/2 [2.1 220117]
    org.graalvm.visualvm.host/2 [2.1 230906]
    org.graalvm.visualvm.application/2 [2.4 230906]
    org.openjdk.btrace.visualvm.api [2.2.2 220411]
    org.graalvm.visualvm.tools/2 [2.3 230906]
    org.graalvm.visualvm.modules.tracer.dynamic/2 [2.1 211018]
    org.openjdk.btrace.visualvm.tracer.deployer [2.1.0 210714]
    org.graalvm.visualvm.coredump/2 [2.1 230906]
    org.graalvm.visualvm.threaddump/2 [2.1 230906]
    org.graalvm.visualvm.charts/2 [2.1 230906]
    org.graalvm.visualvm.lib.jfluid.heap [1.3 230906]
    org.graalvm.visualvm.lib.profiler.oql/2 [2.0 230906]
    org.graalvm.visualvm.lib.profiler.utilities/2 [2.0 230906]
    org.netbeans.modules.settings/1 [1.65 20230511-c4f2d87113]
    org.netbeans.core.windows/2 [2.101 20230511-c4f2d87113]
    org.graalvm.visualvm.lib.profiler.attach/2 [2.1 230906]
    org.graalvm.visualvm.lib.profiler/2 [2.4 230906]
    org.graalvm.visualvm.lib.profiler.heapwalker/2 [2.2 230906]
    org.netbeans.modules.autoupdate.services [1.71 20230511-c4f2d87113]
    org.netbeans.modules.autoupdate.ui [1.62 20230511-c4f2d87113]
    org.graalvm.visualvm.heapviewer/2 [2.8 230906]
    org.graalvm.visualvm.heapdump/2 [2.1 230906]
    org.graalvm.visualvm.application.views/2 [2.1 230906]
    jsyntaxpane.lib/1 [0.9.4.3 200207]
    org.openjdk.btrace.visualvm/2 [2.1.0 210714]
    org.netbeans.libs.flatlaf/1 [1.10 20230511-c4f2d87113]
    org.netbeans.swing.laf.flatlaf [1.9 20230511-c4f2d87113]
    org.netbeans.modules.progress.ui [1.49 20230511-c4f2d87113]
    org.netbeans.modules.options.keymap [1.53 20230511-c4f2d87113]
    org.netbeans.modules.masterfs/2 [2.71.0.2 2 20230511-c4f2d87113]
    org.netbeans.modules.masterfs.ui [2.19.0.2 20230511-c4f2d87113]
    org.netbeans.modules.masterfs.nio2 [1.31 20230511-c4f2d87113]
    org.netbeans.libs.jna/2 [2.13 20230511-c4f2d87113]
    org.netbeans.modules.masterfs.linux [1.29 20230511-c4f2d87113]
    org.netbeans.modules.keyring.fallback [1.24 20230511-c4f2d87113]
    org.netbeans.modules.keyring.impl [1.40 20230511-c4f2d87113]
    org.netbeans.modules.editor.mimelookup.impl/1 [1.48 20230511-c4f2d87113]
    org.netbeans.modules.autoupdate.cli [1.30 20230511-c4f2d87113]
    org.netbeans.libs.jna.platform/2 [2.13 20230511-c4f2d87113]
    org.netbeans.core.ui/1 [1.61 20230511-c4f2d87113]
    org.netbeans.core.network [1.28 20230511-c4f2d87113]
    org.netbeans.core.nativeaccess/1 [1.47 20230511-c4f2d87113]
    org.netbeans.core.multitabs/1 [1.28.0.1 1 20230511-c4f2d87113]
    org.netbeans.core.io.ui/1 [1.46 20230511-c4f2d87113]
    org.graalvm.visualvm.lib.profiler.snaptracer/2 [2.0 230906]
    org.graalvm.visualvm.profiling/2 [2.3 230906]
    org.graalvm.visualvm.sampler.truffle/2 [2.1 230906]
    org.graalvm.visualvm.sampler/2 [2.2 230906]
    org.graalvm.visualvm.sa/2 [2.0 230906]
    org.graalvm.visualvm.modules.startup/2 [2.1 230906]
    org.graalvm.visualvm.profiler/2 [2.1 230906]
    org.graalvm.visualvm.profiler.startup/2 [2.0 200207]
    org.graalvm.visualvm.pluginimporter [1.0 230906]
    org.graalvm.visualvm.modules.visualgc [2.1.3 200207]
    org.graalvm.visualvm.modules.tracer.swing/2 [2.2 211018]
    org.graalvm.visualvm.modules.tracer.monitor/2 [2.0 200207]
    org.graalvm.visualvm.modules.tracer.jvmstat/2 [2.0 200207]
    org.graalvm.visualvm.modules.tracer.jvm/2 [2.2 220117]
    org.graalvm.visualvm.modules.tracer.javafx/2 [2.2 211018]
    org.graalvm.visualvm.modules.tracer.io/2 [2.2 211018]
    org.graalvm.visualvm.modules.tracer.collections/2 [2.2 211018]
    org.graalvm.visualvm.modules.threadinspect/2 [2.0 200207]
    org.graalvm.visualvm.modules.security/2 [2.0 200207]
    org.graalvm.visualvm.modules.oqlsyntax/2 [2.0 200207]
    org.graalvm.visualvm.modules.mbeans/2 [2.0 200207]
    org.graalvm.visualvm.modules.killapp/1 [1.2 200207]
    org.graalvm.visualvm.modules.jconsole/2 [2.0 200207]
    org.graalvm.visualvm.modules.graaljs [1.3 230401]
    org.graalvm.visualvm.modules.extensions/2 [2.0 200207]
    org.graalvm.visualvm.modules.buffermonitor/2 [2.0 200207]
    org.graalvm.visualvm.modules.appui/2 [2.1 230906]
    org.graalvm.visualvm.jvmstat/2 [2.0 230906]
    org.graalvm.visualvm.jvm/2 [2.0 230906]
    org.graalvm.visualvm.jmx/2 [2.2 230906]
    org.graalvm.visualvm.host.views/2 [2.0 230906]
    org.graalvm.visualvm.jfr.streaming [1.3 230906]
    org.graalvm.visualvm.jfr/2 [2.3 230906]
    org.graalvm.visualvm.jfr.jdk9/2 [2.1 230906]
    org.graalvm.visualvm.jfr.jdk11/2 [2.1 230906]
    org.graalvm.visualvm.jfr.generic/2 [2.4 230906]
    org.graalvm.visualvm.host.remote/2 [2.0 230906]
    org.graalvm.visualvm.heapviewer.truffle/2 [2.1 230906]
    org.graalvm.visualvm.heapviewer.console/2 [2.0 230906]
    org.graalvm.visualvm.graalvm/2 [2.0 230906]
    org.graalvm.visualvm.gotosource/2 [2.0 230906]
    org.graalvm.visualvm.attach/2 [2.0 230906]
    net.java.dev.tda/2 [2.4 200909]
    net.java.dev.tda.visualvm.logfile/2 [2.4 200909]
    net.java.dev.tda.visualvm/2 [2.4 200909]
    com.oracle.coherence.plugin.visualvm [1.7.0 1.7.0-20240328 202403280741]
INFO [org.netbeans.core.network.proxy.NetworkProxyReloader]: System network proxy resolver: Gnome
INFO [org.netbeans.core.network.proxy.gnome.GsettingsNetworkProxy]: GSettings system proxy resolver: direct connection
INFO [org.netbeans.core.network.proxy.NetworkProxyReloader]: System network proxy reloading succeeded.
INFO [org.netbeans.core.network.proxy.NetworkProxyReloader]: System network proxy - mode: direct
INFO [org.netbeans.core.network.proxy.NetworkProxyReloader]: System network proxy: fell to default (correct if direct mode went before)
INFO [org.netbeans.ui.metrics.laf]: USG_LOOK_AND_FEEL
Diagnostic information
Input arguments:
    -Djdk.home=/opt/java/jdk-21.0.2+13-58-openjdk
    -Dnetbeans.default_userdir_root=/home/<user_name>/.visualvm
    -Dnetbeans.running.environment=gnome
    -Dnetbeans.dirs=/opt/java/visualvm/visualvm:
    -Dnetbeans.home=/opt/java/visualvm/platform
    -Xms24m
    -Xmx768m
    -Dnetbeans.accept_license_class=org.graalvm.visualvm.modules.startup.AcceptLicense
    -Dnetbeans.importclass=org.graalvm.visualvm.modules.startup.ImportSettings
    -Dsun.jvmstat.perdata.syncWaitMs=10000
    -Dsun.java2d.noddraw=true
    -Dsun.java2d.d3d=false
    -Dorg.netbeans.core.TimeableEventQueue.quantum=360000
    -Dpolyglot.js.nashorn-compat=true
    -Dsun.misc.URLClassPath.disableJarChecking=true
    -Djdk.attach.allowAttachSelf=true
    -Dorg.openide.util.ImageUtilities.level=950
    --add-exports=java.desktop/com.sun.java.swing.plaf.gtk=ALL-UNNAMED
    --add-exports=java.desktop/sun.awt=ALL-UNNAMED
    --add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor.event=ALL-UNNAMED
    --add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED
    --add-exports=java.desktop/sun.swing=ALL-UNNAMED
    --add-exports=jdk.attach/sun.tools.attach=ALL-UNNAMED
    --add-opens=java.desktop/sun.awt.X11=ALL-UNNAMED
    --add-opens=java.desktop/javax.swing.plaf.synth=ALL-UNNAMED
    --add-opens=java.base/java.net=ALL-UNNAMED
    --add-opens=java.base/java.lang.ref=ALL-UNNAMED
    --add-opens=java.base/java.lang=ALL-UNNAMED
    --add-opens=java.desktop/javax.swing=ALL-UNNAMED
    --add-opens=java.desktop/javax.swing.plaf.basic=ALL-UNNAMED
    -XX:+IgnoreUnrecognizedVMOptions
    -Dawt.java2d.opengl=true
    -Dsun.java2d.dpiaware=false
    -Dsun.java2d.uiScale=1
    -Dswing.useSystemFontSettings=false
    -Dnetbeans.plaf.disable.ui.customizations=true
    -XX:+HeapDumpOnOutOfMemoryError
    -XX:HeapDumpPath=/home/<user_name>/.visualvm/2.1.7/var/log/heapdump.hprof
    -Djava.security.manager=allow
Compiler: HotSpot 64-Bit Tiered Compilers
Heap memory usage: initial 24.0MB maximum 768.0MB
Non heap memory usage: initial 7.3MB maximum -1b
Garbage collector: G1 Young Generation (Collections=13 Total time spent=0s)
Garbage collector: G1 Concurrent GC (Collections=8 Total time spent=0s)
Garbage collector: G1 Old Generation (Collections=0 Total time spent=0s)
Classes: loaded=7337 total loaded=7337 unloaded 0
INFO [org.netbeans.core.ui.warmup.DiagnosticTask]: Total memory 67,048,890,368
INFO [null]: Total physical memory 67,048,890,368
thurka commented 1 week ago

Thanks for the log file. I would like to know what is your resolution and DPI and also what are your env. variables connected to HiDPI. Thanks.

BTW: Can you, please, try VisualVM 2.1.8 ? I am curious if it makes any difference.

vyalyh-oleg commented 1 week ago

The actual resolution is 3840x2160, the system scaling (Linux Min UI) is 2, so visually it is 1920x1080 with higher DPI. But for each program it is possible to set env GDK_SCALE=x. For VisualVM I didn't use GDK_SCALE (i described it in the very beginning).

Version 2.1.8 didn't bring nothing new in the ui scaling.

The problem is similar to the one that was in NetBeans a year or two ago (if this is of any help, because they also tied their UI to swing).

Upd.: The GDK_SCALE does almost the same as -Dsun.java2d.uiScale java parameter.

thurka commented 1 week ago

The problem is similar to the one that was in NetBeans a year or two ago (if this is of any help, because they also tied their UI to swing).

Does it implies that it is now fixed in NetBeans? If yes, can you indetifiy NetBeans version where it was fixed? VisualVM 2.1.8 is based on NetBeans Platform 19 from September 2023 and VisualVM 2.1.7 is based on older Netbeans Platform 14. So this was the reason, why I wanted to see if 2.18 makes any difference.

vyalyh-oleg commented 1 week ago

I did some tests with 2.18 (with different combinations of environment GDK_SCALE and visualvm parameters). I think the platform itself is only a half of what may be necessary. E.g. I do not need anymore change the default scale of the NetBeans, but besides the fonts the entire interface (the action pictograms, icons, window borders, etc.) are now true to scale. Уou can't reproduce the described behavior? (in GNOME based DE)