From 9c78730299bc648825e2d36b735bbd49183a7213 Mon Sep 17 00:00:00 2001 From: dholmes Date: Fri, 25 Mar 2011 07:09:38 -0400 Subject: [PATCH] 7030063: AWT support for SE-Embedded integration Summary: AWT support for SE-Embedded Reviewed-by: anthony, art, bobv, collins, alanb --- make/launchers/Makefile | 13 +- make/sun/Makefile | 15 +- make/sun/awt/mawt.gmk | 16 +- make/sun/jawt/Makefile | 15 +- make/sun/jpeg/Makefile | 3 +- make/sun/security/tools/Makefile | 4 +- make/sun/xawt/Makefile | 21 +- src/share/classes/java/awt/Toolkit.java | 4 +- src/share/classes/sun/awt/HToolkit.java | 378 ++++++++++++++++++ src/solaris/classes/sun/awt/X11/XToolkit.java | 8 +- .../classes/sun/awt/X11/XTrayIconPeer.java | 4 +- src/solaris/native/java/lang/java_props_md.c | 44 +- src/solaris/native/sun/awt/jawt.c | 7 +- src/solaris/native/sun/xawt/XToolkit.c | 128 +++++- 14 files changed, 611 insertions(+), 49 deletions(-) create mode 100644 src/share/classes/sun/awt/HToolkit.java diff --git a/make/launchers/Makefile b/make/launchers/Makefile index 8d7036be1..cc07bbe9c 100644 --- a/make/launchers/Makefile +++ b/make/launchers/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2004, 2011, 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 @@ -44,8 +44,17 @@ $(MAKE) -f Makefile.launcher \ endef # Run MAKE $@ for all generic launchers -define make-all-launchers +ifndef BUILD_HEADLESS_ONLY +define make-appletviewer $(call make-launcher, appletviewer, sun.applet.Main, , ) +endef +else +define make-appletviewer +endef +endif + +define make-all-launchers +$(make-appletviewer) $(call make-launcher, apt, com.sun.tools.apt.Main, , ) $(call make-launcher, extcheck, com.sun.tools.extcheck.Main, , ) $(call make-launcher, idlj, com.sun.tools.corba.se.idl.toJavaPortable.Compile, , ) diff --git a/make/sun/Makefile b/make/sun/Makefile index cac9b8781..6e0830cd1 100644 --- a/make/sun/Makefile +++ b/make/sun/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1995, 2011, 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 @@ -69,10 +69,17 @@ endif # nio need to be compiled before awt to have all charsets ready SUBDIRS = jar security javazic misc net nio text launcher + +ifdef BUILD_HEADLESS_ONLY + DISPLAY_LIBS = awt $(HEADLESS_SUBDIR) + DISPLAY_TOOLS = +else + DISPLAY_LIBS = awt splashscreen $(XAWT_SUBDIR) $(HEADLESS_SUBDIR) + DISPLAY_TOOLS = applet +endif SUBDIRS_desktop = audio $(RENDER_SUBDIR) image \ - awt splashscreen $(XAWT_SUBDIR) \ - $(HEADLESS_SUBDIR) $(DGA_SUBDIR) \ - jawt font jpeg cmm applet beans + $(DISPLAY_LIBS) $(DGA_SUBDIR) \ + jawt font jpeg cmm $(DISPLAY_TOOLS) beans SUBDIRS_management = management SUBDIRS_misc = $(ORG_SUBDIR) rmi $(JDBC_SUBDIR) tracing SUBDIRS_tools = native2ascii serialver tools jconsole diff --git a/make/sun/awt/mawt.gmk b/make/sun/awt/mawt.gmk index 44de69260..f8160ee7d 100644 --- a/make/sun/awt/mawt.gmk +++ b/make/sun/awt/mawt.gmk @@ -1,5 +1,5 @@ # -# Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2000, 2011, 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 @@ -149,13 +149,13 @@ ifeq ($(PLATFORM), linux) LIBXT = -lXt else # Allows for builds on Debian GNU Linux, X11 is in a different place - LIBXT = $(firstword $(wildcard /usr/X11R6/lib/libXt.a) \ + LIBXT = $(firstword $(wildcard $(OPENWIN_LIB)/libXt.a) \ $(wildcard /usr/lib/libXt.a)) - LIBSM = $(firstword $(wildcard /usr/X11R6/lib/libSM.a) \ + LIBSM = $(firstword $(wildcard $(OPENWIN_LIB)/libSM.a) \ $(wildcard /usr/lib/libSM.a)) - LIBICE = $(firstword $(wildcard /usr/X11R6/lib/libICE.a) \ + LIBICE = $(firstword $(wildcard $(OPENWIN_LIB)/libICE.a) \ $(wildcard /usr/lib/libICE.a)) - LIBXTST = $(firstword $(wildcard /usr/X11R6/lib/libXtst.a) \ + LIBXTST = $(firstword $(wildcard $(OPENWIN_LIB)/libXtst.a) \ $(wildcard /usr/lib/libXtst.a)) endif endif @@ -224,9 +224,9 @@ CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGDIR)/debug \ $(EVENT_MODEL) ifeq ($(PLATFORM), linux) -# Checking for the X11/extensions headers at the additional location - CPPFLAGS += -I/X11R6/include/X11/extensions \ - -I/usr/include/X11/extensions + # Checking for the X11/extensions headers at the additional location + CPPFLAGS += -I$(firstword $(wildcard $(OPENWIN_HOME)/include/X11/extensions) \ + $(wildcard /usr/include/X11/extensions)) endif ifeq ($(PLATFORM), solaris) diff --git a/make/sun/jawt/Makefile b/make/sun/jawt/Makefile index 7741e1b5a..afbce78e6 100644 --- a/make/sun/jawt/Makefile +++ b/make/sun/jawt/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1999, 2011, 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 @@ -112,11 +112,20 @@ CPPFLAGS += -I$(OPENWIN_HOME)/include \ # Libraries to link in. # ifeq ($(PLATFORM), solaris) -OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -L$(OPENWIN_LIB) -L$(LIBDIR)/$(LIBARCH)/xawt -lmawt -L/usr/openwin/sfw/lib$(ISA_DIR) -lXrender + ifndef BUILD_HEADLESS_ONLY + OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -L$(OPENWIN_LIB) -L$(LIBDIR)/$(LIBARCH)/xawt -lmawt -L/usr/openwin/sfw/lib$(ISA_DIR) -lXrender + else + OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -L$(OPENWIN_LIB) -L$(LIBDIR)/$(LIBARCH)/headless -lmawt -L/usr/openwin/sfw/lib$(ISA_DIR) -lXrender + endif endif # PLATFORM ifeq ($(PLATFORM), linux) -OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -lawt -L$(LIBDIR)/$(LIBARCH)/xawt -lmawt + ifndef BUILD_HEADLESS_ONLY + OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -lawt -L$(LIBDIR)/$(LIBARCH)/xawt -lmawt + else + OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -lawt -L$(LIBDIR)/$(LIBARCH)/headless -lmawt + CFLAGS += -DHEADLESS + endif endif # PLATFORM endif # PLATFORM diff --git a/make/sun/jpeg/Makefile b/make/sun/jpeg/Makefile index 78c53c461..880fc7c5e 100644 --- a/make/sun/jpeg/Makefile +++ b/make/sun/jpeg/Makefile @@ -73,9 +73,10 @@ ifeq ($(PLATFORM), linux) # Recommended way to avoid such warning is to declare the variable as # volatile to prevent the optimization. However, this approach does not # work because we have to declare all variables as volatile in result. - +ifndef CROSS_COMPILE_ARCH OTHER_CFLAGS += -Wno-clobbered endif +endif include $(BUILDDIR)/common/Mapfile-vers.gmk include $(BUILDDIR)/common/Library.gmk diff --git a/make/sun/security/tools/Makefile b/make/sun/security/tools/Makefile index bfdb261f6..f46070d07 100644 --- a/make/sun/security/tools/Makefile +++ b/make/sun/security/tools/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1997, 2011, 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 @@ -46,5 +46,7 @@ include $(BUILDDIR)/common/Classes.gmk build: $(call make-launcher, keytool, sun.security.tools.KeyTool, , ) +ifndef BUILD_HEADLESS_ONLY $(call make-launcher, policytool, sun.security.tools.policytool.PolicyTool, , ) +endif diff --git a/make/sun/xawt/Makefile b/make/sun/xawt/Makefile index afe16f573..cf322d902 100644 --- a/make/sun/xawt/Makefile +++ b/make/sun/xawt/Makefile @@ -1,5 +1,5 @@ # -# Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2002, 2011, 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 @@ -129,10 +129,17 @@ CPPFLAGS += -DXAWT -DXAWT_HACK \ -I$(PLATFORM_SRC)/native/sun/awt ifeq ($(PLATFORM), linux) -# Allows for builds on Debian GNU Linux, X11 is in a different place - CPPFLAGS += -I/usr/X11R6/include/X11/extensions \ - -I/usr/include/X11/extensions \ - -I$(OPENWIN_HOME)/include + ifndef CROSS_COMPILE_ARCH + # Allows for builds on Debian GNU Linux, X11 is in a different place + # This should really be handled at a higher-level so we don't have to + # work-around this when cross-compiling + CPPFLAGS += -I/usr/X11R6/include/X11/extensions \ + -I/usr/include/X11/extensions \ + -I$(OPENWIN_HOME)/include + else + CPPFLAGS += -I$(OPENWIN_HOME)/include/X11/extensions \ + -I$(OPENWIN_HOME)/include + endif endif # We have some odd logic here because some Solaris 10 updates @@ -245,7 +252,11 @@ XLIBTYPES=$(PLATFORM_SRC)/classes/sun/awt/X11/generator/xlibtypes.txt $(SIZERS): $(SIZERS_C) $(prep-target) +ifndef CROSS_COMPILE_ARCH $(CC) $(CFLAGS_$(subst .,,$(suffix $@))) $(CPPFLAGS) -o $@ $(SIZER)$(suffix $@).c +else + $(HOST_CC) $(CPPFLAGS) -o $@ $(SIZER)$(suffix $@).c +endif $(WRAPPER_GENERATOR_CLASS): $(WRAPPER_GENERATOR_JAVA) $(prep-target) diff --git a/src/share/classes/java/awt/Toolkit.java b/src/share/classes/java/awt/Toolkit.java index 85ee6db4a..aa10f201c 100644 --- a/src/share/classes/java/awt/Toolkit.java +++ b/src/share/classes/java/awt/Toolkit.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2011, 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 @@ -858,7 +858,7 @@ public abstract class Toolkit { String nm = null; Class cls = null; try { - nm = System.getProperty("awt.toolkit", "sun.awt.X11.XToolkit"); + nm = System.getProperty("awt.toolkit"); try { cls = Class.forName(nm); } catch (ClassNotFoundException e) { diff --git a/src/share/classes/sun/awt/HToolkit.java b/src/share/classes/sun/awt/HToolkit.java new file mode 100644 index 000000000..edadb84f3 --- /dev/null +++ b/src/share/classes/sun/awt/HToolkit.java @@ -0,0 +1,378 @@ +/* + * Copyright (c) 2011, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 sun.awt; + +import java.awt.*; +import java.awt.dnd.*; +import java.awt.dnd.peer.DragSourceContextPeer; +import java.awt.im.InputMethodHighlight; +import java.awt.im.spi.InputMethodDescriptor; +import java.awt.image.*; +import java.awt.datatransfer.Clipboard; +import java.awt.peer.*; +import java.util.Map; +import java.util.Properties; + +/* + * HToolkit is a platform independent Toolkit used + * with the HeadlessToolkit. It is primarily used + * in embedded JRE's that do not have sun/awt/X11 classes. + */ +public class HToolkit extends SunToolkit + implements ComponentFactory { + + public HToolkit() { + } + + /* + * Component peer objects - unsupported. + */ + + public WindowPeer createWindow(Window target) + throws HeadlessException { + throw new HeadlessException(); + } + + public FramePeer createFrame(Frame target) + throws HeadlessException { + throw new HeadlessException(); + } + + public DialogPeer createDialog(Dialog target) + throws HeadlessException { + throw new HeadlessException(); + } + + public ButtonPeer createButton(Button target) + throws HeadlessException { + throw new HeadlessException(); + } + + public TextFieldPeer createTextField(TextField target) + throws HeadlessException { + throw new HeadlessException(); + } + + public ChoicePeer createChoice(Choice target) + throws HeadlessException { + throw new HeadlessException(); + } + + public LabelPeer createLabel(Label target) + throws HeadlessException { + throw new HeadlessException(); + } + + public ListPeer createList(List target) + throws HeadlessException { + throw new HeadlessException(); + } + + public CheckboxPeer createCheckbox(Checkbox target) + throws HeadlessException { + throw new HeadlessException(); + } + + public ScrollbarPeer createScrollbar(Scrollbar target) + throws HeadlessException { + throw new HeadlessException(); + } + + public ScrollPanePeer createScrollPane(ScrollPane target) + throws HeadlessException { + throw new HeadlessException(); + } + + public TextAreaPeer createTextArea(TextArea target) + throws HeadlessException { + throw new HeadlessException(); + } + + public FileDialogPeer createFileDialog(FileDialog target) + throws HeadlessException { + throw new HeadlessException(); + } + + public MenuBarPeer createMenuBar(MenuBar target) + throws HeadlessException { + throw new HeadlessException(); + } + + public MenuPeer createMenu(Menu target) + throws HeadlessException { + throw new HeadlessException(); + } + + public PopupMenuPeer createPopupMenu(PopupMenu target) + throws HeadlessException { + throw new HeadlessException(); + } + + public MenuItemPeer createMenuItem(MenuItem target) + throws HeadlessException { + throw new HeadlessException(); + } + + public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) + throws HeadlessException { + throw new HeadlessException(); + } + + public DragSourceContextPeer createDragSourceContextPeer( + DragGestureEvent dge) + throws InvalidDnDOperationException { + throw new InvalidDnDOperationException("Headless environment"); + } + + public RobotPeer createRobot(Robot target, GraphicsDevice screen) + throws AWTException, HeadlessException { + throw new HeadlessException(); + } + + public KeyboardFocusManagerPeer createKeyboardFocusManagerPeer(KeyboardFocusManager manager) { + // See 6833019. + return + new KeyboardFocusManagerPeer() { + public Window getCurrentFocusedWindow() { return null; } + public void setCurrentFocusOwner(Component comp) {} + public Component getCurrentFocusOwner() { return null; } + public void clearGlobalFocusOwner(Window activeWindow) {} + }; + } + + public TrayIconPeer createTrayIcon(TrayIcon target) + throws HeadlessException { + throw new HeadlessException(); + } + + public SystemTrayPeer createSystemTray(SystemTray target) + throws HeadlessException { + throw new HeadlessException(); + } + + public boolean isTraySupported() { + return false; + } + + public GlobalCursorManager getGlobalCursorManager() + throws HeadlessException { + throw new HeadlessException(); + } + + /* + * Headless toolkit - unsupported. + */ + protected void loadSystemColors(int[] systemColors) + throws HeadlessException { + throw new HeadlessException(); + } + + public ColorModel getColorModel() + throws HeadlessException { + throw new HeadlessException(); + } + + public int getScreenResolution() + throws HeadlessException { + throw new HeadlessException(); + } + + public Map mapInputMethodHighlight(InputMethodHighlight highlight) + throws HeadlessException { + throw new HeadlessException(); + } + + public int getMenuShortcutKeyMask() + throws HeadlessException { + throw new HeadlessException(); + } + + public boolean getLockingKeyState(int keyCode) + throws UnsupportedOperationException { + throw new HeadlessException(); + } + + public void setLockingKeyState(int keyCode, boolean on) + throws UnsupportedOperationException { + throw new HeadlessException(); + } + + public Cursor createCustomCursor(Image cursor, Point hotSpot, String name) + throws IndexOutOfBoundsException, HeadlessException { + throw new HeadlessException(); + } + + public Dimension getBestCursorSize(int preferredWidth, int preferredHeight) + throws HeadlessException { + throw new HeadlessException(); + } + + public int getMaximumCursorColors() + throws HeadlessException { + throw new HeadlessException(); + } + + public T + createDragGestureRecognizer(Class abstractRecognizerClass, + DragSource ds, Component c, + int srcActions, DragGestureListener dgl) + { + return null; + } + + public int getScreenHeight() + throws HeadlessException { + throw new HeadlessException(); + } + + public int getScreenWidth() + throws HeadlessException { + throw new HeadlessException(); + } + + public Dimension getScreenSize() + throws HeadlessException { + throw new HeadlessException(); + } + + public Insets getScreenInsets(GraphicsConfiguration gc) + throws HeadlessException { + throw new HeadlessException(); + } + + public void setDynamicLayout(boolean dynamic) + throws HeadlessException { + throw new HeadlessException(); + } + + protected boolean isDynamicLayoutSet() + throws HeadlessException { + throw new HeadlessException(); + } + + public boolean isDynamicLayoutActive() + throws HeadlessException { + throw new HeadlessException(); + } + + public Clipboard getSystemClipboard() + throws HeadlessException { + throw new HeadlessException(); + } + + /* + * Printing + */ + public PrintJob getPrintJob(Frame frame, String jobtitle, + JobAttributes jobAttributes, + PageAttributes pageAttributes) { + if (frame != null) { + // Should never happen + throw new HeadlessException(); + } + throw new IllegalArgumentException( + "PrintJob not supported in a headless environment"); + } + + public PrintJob getPrintJob(Frame frame, String doctitle, Properties props) + { + if (frame != null) { + // Should never happen + throw new HeadlessException(); + } + throw new IllegalArgumentException( + "PrintJob not supported in a headless environment"); + } + + /* + * Headless toolkit - supported. + */ + + public void sync() { + // Do nothing + } + + protected boolean syncNativeQueue(final long timeout) { + return false; + } + + public void beep() { + // Send alert character + System.out.write(0x07); + } + + + /* + * Fonts + */ + public FontPeer getFontPeer(String name, int style) { + return (FontPeer)null; + } + + /* + * Modality + */ + public boolean isModalityTypeSupported(Dialog.ModalityType modalityType) { + return false; + } + + public boolean isModalExclusionTypeSupported(Dialog.ModalExclusionType exclusionType) { + return false; + } + + public boolean isDesktopSupported() { + return false; + } + + public DesktopPeer createDesktopPeer(Desktop target) + throws HeadlessException{ + throw new HeadlessException(); + } + + public boolean isWindowOpacityControlSupported() { + return false; + } + + public boolean isWindowShapingSupported() { + return false; + } + + public boolean isWindowTranslucencySupported() { + return false; + } + + public void grab(Window w) { } + + public void ungrab(Window w) { } + + protected boolean syncNativeQueue() { return false; } + + public InputMethodDescriptor getInputMethodAdapterDescriptor() + throws AWTException + { + return (InputMethodDescriptor)null; + } +} diff --git a/src/solaris/classes/sun/awt/X11/XToolkit.java b/src/solaris/classes/sun/awt/X11/XToolkit.java index ad92d2e9c..a8dd37aae 100644 --- a/src/solaris/classes/sun/awt/X11/XToolkit.java +++ b/src/solaris/classes/sun/awt/X11/XToolkit.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 @@ -135,6 +135,12 @@ public final class XToolkit extends UNIXToolkit implements Runnable { noisyAwtHandler = AccessController.doPrivileged(new GetBooleanAction("sun.awt.noisyerrorhandler")); } + /* + * Return (potentially) platform specific display timeout for the + * tray icon + */ + static native long getTrayIconDisplayTimeout(); + //---- ERROR HANDLER CODE ----// /* diff --git a/src/solaris/classes/sun/awt/X11/XTrayIconPeer.java b/src/solaris/classes/sun/awt/X11/XTrayIconPeer.java index ff7b78e2c..7bc452c96 100644 --- a/src/solaris/classes/sun/awt/X11/XTrayIconPeer.java +++ b/src/solaris/classes/sun/awt/X11/XTrayIconPeer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2011, 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 @@ -230,7 +230,7 @@ public class XTrayIconPeer implements TrayIconPeer, // Wait till the EmbeddedFrame is reparented long start = System.currentTimeMillis(); - final long PERIOD = 2000L; + final long PERIOD = XToolkit.getTrayIconDisplayTimeout(); XToolkit.awtLock(); try { while (!isTrayIconDisplayed) { diff --git a/src/solaris/native/java/lang/java_props_md.c b/src/solaris/native/java/lang/java_props_md.c index 1e4e3b6d6..0a24f8653 100644 --- a/src/solaris/native/java/lang/java_props_md.c +++ b/src/solaris/native/java/lang/java_props_md.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2011, 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 @@ -55,6 +55,11 @@ #endif #endif +#ifdef JAVASE_EMBEDDED +#include +#include +#endif + /* Take an array of string pairs (map of key->value) and a string (key). * Examine each pair in the map to see if the first string (key) matches the * string. If so, store the second string of the pair (value) in the value and @@ -304,6 +309,36 @@ static int ParseLocale(int cat, char ** std_language, char ** std_script, return 1; } +#ifdef JAVASE_EMBEDDED +/* Determine the default embedded toolkit based on whether lib/xawt/ + * exists in the JRE. This can still be overridden by -Dawt.toolkit=XXX + */ +static char* getEmbeddedToolkit() { + Dl_info dlinfo; + char buf[MAXPATHLEN]; + int32_t len; + char *p; + struct stat statbuf; + + /* Get address of this library and the directory containing it. */ + dladdr((void *)getEmbeddedToolkit, &dlinfo); + realpath((char *)dlinfo.dli_fname, buf); + len = strlen(buf); + p = strrchr(buf, '/'); + /* Default AWT Toolkit on Linux and Solaris is XAWT. */ + strncpy(p, "/xawt/", MAXPATHLEN-len-1); + /* Check if it exists */ + if (stat(buf, &statbuf) == -1 && errno == ENOENT) { + /* No - this is a reduced-headless-jre so use special HToolkit */ + return "sun.awt.HToolkit"; + } + else { + /* Yes - this is a headful JRE so fallback to SE defaults */ + return NULL; + } +} +#endif + /* This function gets called very early, before VM_CALLS are setup. * Do not use any of the VM_CALLS entries!!! */ @@ -328,7 +363,12 @@ GetJavaProperties(JNIEnv *env) /* Java 2D properties */ sprops.graphics_env = "sun.awt.X11GraphicsEnvironment"; - sprops.awt_toolkit = NULL; + +#ifdef JAVASE_EMBEDDED + sprops.awt_toolkit = getEmbeddedToolkit(); + if (sprops.awt_toolkit == NULL) // default as below +#endif + sprops.awt_toolkit = "sun.awt.X11.XToolkit"; /* This is used only for debugging of font problems. */ v = getenv("JAVA2D_FONTPATH"); diff --git a/src/solaris/native/sun/awt/jawt.c b/src/solaris/native/sun/awt/jawt.c index b682edaf4..f6f8530cb 100644 --- a/src/solaris/native/sun/awt/jawt.c +++ b/src/solaris/native/sun/awt/jawt.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2011, 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 @@ -33,6 +33,10 @@ */ JNIEXPORT jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt) { +#if defined(JAVASE_EMBEDDED) && defined(HEADLESS) + /* there are no AWT libs available at all */ + return JNI_FALSE; +#else if (awt == NULL) { return JNI_FALSE; } @@ -51,4 +55,5 @@ JNIEXPORT jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt) } return JNI_TRUE; +#endif } diff --git a/src/solaris/native/sun/xawt/XToolkit.c b/src/solaris/native/sun/xawt/XToolkit.c index 4ea63143c..69620ffc1 100644 --- a/src/solaris/native/sun/xawt/XToolkit.c +++ b/src/solaris/native/sun/xawt/XToolkit.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 2011, 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 @@ -110,6 +110,21 @@ Java_sun_awt_X11_XToolkit_initIDs awt_ModLockIsShiftLock = (*env)->GetStaticIntField(env, clazz, fid) != 0 ? True : False; } +/* + * Class: sun_awt_X11_XToolkit + * Method: getTrayIconDisplayTimeout + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_sun_awt_X11_XToolkit_getTrayIconDisplayTimeout + (JNIEnv *env, jclass clazz) +{ +#ifndef JAVASE_EMBEDDED + return (jlong) 2000; +#else + return (jlong) 10000; +#endif +} + /* * Class: sun_awt_X11_XToolkit * Method: getDefaultXColormap @@ -340,15 +355,34 @@ static uint32_t get_poll_timeout(jlong nextTaskTime); #define AWT_READPIPE (awt_pipe_fds[0]) #define AWT_WRITEPIPE (awt_pipe_fds[1]) -#define DEF_AWT_MAX_POLL_TIMEOUT ((uint32_t)500) /* milliseconds */ +#ifdef JAVASE_EMBEDDED + #define DEF_AWT_MAX_POLL_TIMEOUT ((uint32_t)4000000000) /* milliseconds */ +#else + #define DEF_AWT_MAX_POLL_TIMEOUT ((uint32_t)500) /* milliseconds */ +#endif + #define DEF_AWT_FLUSH_TIMEOUT ((uint32_t)100) /* milliseconds */ #define AWT_MIN_POLL_TIMEOUT ((uint32_t)0) /* milliseconds */ #define TIMEOUT_TIMEDOUT 0 #define TIMEOUT_EVENTS 1 +/* awt_poll_alg - AWT Poll Events Aging Algorithms */ +#define AWT_POLL_FALSE 1 +#define AWT_POLL_AGING_SLOW 2 +#define AWT_POLL_AGING_FAST 3 + +#define AWT_POLL_THRESHOLD 1000 // msec, Block if delay is larger +#define AWT_POLL_BLOCK -1 // cause poll() block + // Static fields +#ifdef JAVASE_EMBEDDED + static int awt_poll_alg = AWT_POLL_AGING_FAST; +#else + static int awt_poll_alg = AWT_POLL_AGING_SLOW; +#endif + static uint32_t AWT_FLUSH_TIMEOUT = DEF_AWT_FLUSH_TIMEOUT; /* milliseconds */ static uint32_t AWT_MAX_POLL_TIMEOUT = DEF_AWT_MAX_POLL_TIMEOUT; /* milliseconds */ static pthread_t awt_MainThread = 0; @@ -417,6 +451,7 @@ awt_pipe_init() { */ static void readEnv() { char * value; + int tmp_poll_alg; static Boolean env_read = False; if (env_read) return; @@ -451,6 +486,23 @@ static void readEnv() { if (static_poll_timeout != 0) { curPollTimeout = static_poll_timeout; } + + // non-blocking poll() + value = getenv("_AWT_POLL_ALG"); + if (value != NULL) { + tmp_poll_alg = atoi(value); + switch(tmp_poll_alg) { + case AWT_POLL_FALSE: + case AWT_POLL_AGING_SLOW: + case AWT_POLL_AGING_FAST: + awt_poll_alg = tmp_poll_alg; + break; + default: + PRINT("Unknown value of _AWT_POLL_ALG, assuming Slow Aging Algorithm by default"); + awt_poll_alg = AWT_POLL_AGING_SLOW; + break; + } + } } /** @@ -478,14 +530,29 @@ static void update_poll_timeout(int timeout_control) { if (static_poll_timeout != 0) return; // Update it otherwise - if (timeout_control == TIMEOUT_TIMEDOUT) { - /* add 1/4 (plus 1, in case the division truncates to 0) */ - curPollTimeout += ((curPollTimeout>>2) + 1); - curPollTimeout = min(AWT_MAX_POLL_TIMEOUT, curPollTimeout); - } else if (timeout_control == TIMEOUT_EVENTS) { - /* subtract 1/4 (plus 1, in case the division truncates to 0) */ - curPollTimeout -= ((curPollTimeout>>2) + 1); - curPollTimeout = max(AWT_MIN_POLL_TIMEOUT, curPollTimeout); + + switch(awt_poll_alg) { + case AWT_POLL_AGING_SLOW: + if (timeout_control == TIMEOUT_TIMEDOUT) { + /* add 1/4 (plus 1, in case the division truncates to 0) */ + curPollTimeout += ((curPollTimeout>>2) + 1); + curPollTimeout = min(AWT_MAX_POLL_TIMEOUT, curPollTimeout); + } else if (timeout_control == TIMEOUT_EVENTS) { + /* subtract 1/4 (plus 1, in case the division truncates to 0) */ + curPollTimeout -= ((curPollTimeout>>2) + 1); + curPollTimeout = max(AWT_MIN_POLL_TIMEOUT, curPollTimeout); + } + break; + case AWT_POLL_AGING_FAST: + if (timeout_control == TIMEOUT_TIMEDOUT) { + curPollTimeout += ((curPollTimeout>>2) + 1); + curPollTimeout = min(AWT_MAX_POLL_TIMEOUT, curPollTimeout); + if((int)curPollTimeout > AWT_POLL_THRESHOLD || (int)curPollTimeout == AWT_POLL_BLOCK) + curPollTimeout = AWT_POLL_BLOCK; + } else if (timeout_control == TIMEOUT_EVENTS) { + curPollTimeout = max(AWT_MIN_POLL_TIMEOUT, 1); + } + break; } } @@ -497,16 +564,37 @@ static void update_poll_timeout(int timeout_control) { */ static uint32_t get_poll_timeout(jlong nextTaskTime) { + uint32_t ret_timeout; + uint32_t timeout; + uint32_t taskTimeout; + uint32_t flushTimeout; + jlong curTime = awtJNI_TimeMillis(); - uint32_t timeout = curPollTimeout; - uint32_t taskTimeout = (nextTaskTime == -1) ? AWT_MAX_POLL_TIMEOUT : (uint32_t)max(0, (int32_t)(nextTaskTime - curTime)); - uint32_t flushTimeout = (awt_next_flush_time > 0) ? (uint32_t)max(0, (int32_t)(awt_next_flush_time - curTime)) : AWT_MAX_POLL_TIMEOUT; + timeout = curPollTimeout; + switch(awt_poll_alg) { + case AWT_POLL_AGING_SLOW: + case AWT_POLL_AGING_FAST: + taskTimeout = (nextTaskTime == -1) ? AWT_MAX_POLL_TIMEOUT : (uint32_t)max(0, (int32_t)(nextTaskTime - curTime)); + flushTimeout = (awt_next_flush_time > 0) ? (uint32_t)max(0, (int32_t)(awt_next_flush_time - curTime)) : AWT_MAX_POLL_TIMEOUT; + + PRINT2("to: %d, ft: %d, to: %d, tt: %d, mil: %d\n", taskTimeout, flushTimeout, timeout, (int)nextTaskTime, (int)curTime); + + // Adjust timeout to flush_time and task_time + ret_timeout = min(flushTimeout, min(taskTimeout, timeout)); + if((int)curPollTimeout == AWT_POLL_BLOCK) + ret_timeout = AWT_POLL_BLOCK; + break; + + case AWT_POLL_FALSE: + ret_timeout = (nextTaskTime > curTime) ? + (nextTaskTime - curTime) : + ((nextTaskTime == -1) ? -1 : 0); + break; + } - PRINT2("to: %d, ft: %d, to: %d, tt: %d, mil: %d\n", taskTimeout, flushTimeout, timeout, (int)nextTaskTime, (int)curTime); + return ret_timeout; - // Adjust timeout to flush_time and task_time - return min(flushTimeout, min(taskTimeout, timeout)); -} /* awt_get_poll_timeout() */ +} /* get_poll_timeout() */ /* * Waits for X/Xt events to appear on the pipe. Returns only when @@ -598,6 +686,8 @@ performPoll(JNIEnv *env, jlong nextTaskTime) { if (result == 0) { /* poll() timed out -- update timeout value */ update_poll_timeout(TIMEOUT_TIMEDOUT); + PRINT2("%s(): TIMEOUT_TIMEDOUT curPollTimeout = %d \n", + performPoll, curPollTimeout); } if (pollFds[1].revents) { int count; @@ -606,10 +696,14 @@ performPoll(JNIEnv *env, jlong nextTaskTime) { do { count = read(AWT_READPIPE, read_buf, AWT_POLL_BUFSIZE ); } while (count == AWT_POLL_BUFSIZE ); + PRINT2("%s(): data on the AWT pipe: curPollTimeout = %d \n", + performPoll, curPollTimeout); } if (pollFds[0].revents) { // Events in X pipe update_poll_timeout(TIMEOUT_EVENTS); + PRINT2("%s(): TIMEOUT_EVENTS curPollTimeout = %ld \n", + performPoll, curPollTimeout); } return; -- GitLab