changeset 6551:8bc401414049

7191018: Manual test closed/java/awt/JAWT causes JVM to crash starting from JDK 5 7190587: Open source and jtreg'ify JAWT regression test Reviewed-by: anthony, serb
author alitvinov
date Mon, 19 Aug 2013 16:40:38 +0400
parents 5e4c3fbac69b
children df8dd2c6a7ca
files src/solaris/native/sun/awt/awt_DrawingSurface.c test/java/awt/JAWT/JAWT.sh test/java/awt/JAWT/Makefile.cygwin test/java/awt/JAWT/Makefile.unix test/java/awt/JAWT/Makefile.win test/java/awt/JAWT/MyCanvas.java test/java/awt/JAWT/myfile.c test/java/awt/JAWT/myfile.cpp
diffstat 8 files changed, 614 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/native/sun/awt/awt_DrawingSurface.c	Tue Apr 02 10:32:21 2013 +0200
+++ b/src/solaris/native/sun/awt/awt_DrawingSurface.c	Mon Aug 19 16:40:38 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2013, 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
@@ -405,7 +405,14 @@
         target = (*env)->GetObjectField(env, peer, mComponentPeerIDs.target);
     }
 #else
-    target =  (*env)->GetObjectField(env, peer, targetID);
+    if (window != None) {
+        peer = JNU_CallStaticMethodByName(env, NULL, "sun/awt/X11/XToolkit",
+            "windowToXWindow", "(J)Lsun/awt/X11/XBaseWindow;", (jlong)window).l;
+    }
+    if ((peer != NULL) &&
+        (JNU_IsInstanceOfByName(env, peer, "sun/awt/X11/XWindow") == 1)) {
+        target = (*env)->GetObjectField(env, peer, targetID);
+    }
 #endif
 
     if (target == NULL) {
@@ -414,7 +421,6 @@
         return (jobject)NULL;
     }
 
-
     AWT_UNLOCK();
 
     return target;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/JAWT/JAWT.sh	Mon Aug 19 16:40:38 2013 +0400
@@ -0,0 +1,173 @@
+#!/bin/sh
+
+# Copyright (c) 2013, 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.
+
+# @test JAWT.sh
+# @bug 7190587
+# @summary Tests Java AWT native interface library
+# @author kshefov
+# @run shell JAWT.sh
+
+# NB: To run on Windows with MKS and Visual Studio compiler
+# add the following options to jtreg: -e INCLUDE="%INCLUDE%;." -e LIB="%LIB%;."
+
+if [ "${TESTSRC}" = "" ]
+then TESTSRC=.
+fi
+
+if [ "${TESTJAVA}" = "" ]
+then
+  PARENT=`dirname \`which java\``
+  TESTJAVA=`dirname ${PARENT}`
+  echo "TESTJAVA not set, selecting " ${TESTJAVA}
+  echo "If this is incorrect, try setting the variable manually."
+fi
+
+# set platform-dependent variables
+OS=`uname -s`
+case "$OS" in
+  Linux )
+    NULL=/dev/null
+    PS=":"
+    FS="/"
+    ${TESTJAVA}${FS}bin${FS}java -version 2>&1 | grep '64-Bit' > $NULL
+    if [ $? -eq '0' ]
+    then
+        ARCH="amd64"
+    else
+        ARCH="i386"
+    fi
+    SYST="linux"
+    MAKEFILE="Makefile.unix"
+    CC="gcc"
+	MAKE="make"
+	LD_LIBRARY_PATH=".":${TESTJAVA}${FS}jre${FS}lib${FS}${ARCH}
+    ;;
+  SunOS )
+    NULL=/dev/null
+    PS=":"
+    FS="/"
+    if [ `uname -p | grep -c 'sparc'` -gt '0' ]
+    then
+        ARCH="sparc"
+    else
+        ARCH="i386"
+    fi
+    SYST="solaris"
+    MAKEFILE="Makefile.unix"
+    CC="gcc"
+	MAKE="make"
+	LD_LIBRARY_PATH=".":${TESTJAVA}${FS}jre${FS}lib${FS}${ARCH}
+    ;;
+  Windows* )
+    NULL=null
+    PS=";"
+    FS="\\"
+    MAKEFILE="Makefile.win"
+    CC="cl"
+	MAKE="nmake"
+	${TESTJAVA}${FS}bin${FS}java -d64 -version 2>&1 | grep '64-Bit' > $NULL
+    if [ "$?" -eq '0' ]
+    then
+        ARCH="amd64"
+    else
+        ARCH="i386"
+    fi
+	SYST="windows"
+    ;;
+  CYGWIN* )
+    NULL=/dev/null
+    PS=":"
+    FS="/"
+    MAKEFILE="Makefile.cygwin"
+    CC="gcc"
+	${TESTJAVA}${FS}bin${FS}java -d64 -version 2>&1 | grep '64-Bit' > $NULL
+    if [ "$?" -eq '0' ]
+    then
+        ARCH="amd64"
+    else
+        ARCH="i386"
+    fi
+	SYST="cygwin"	
+	MAKE="make"
+    ;;
+  Darwin )
+    echo "Test passed. This test is not for MacOS."
+    exit 0;
+    ;;
+  * )
+    echo "Unrecognized system!"
+    exit 1;
+    ;;
+esac
+
+# Skip unsupported platforms
+case `uname -m` in
+    arm* | ppc* )
+      echo "Test passed. Not supported on current architecture."
+      exit 0
+      ;;
+esac
+
+echo "OS-ARCH is" ${SYST}-${ARCH}
+${TESTJAVA}${FS}jre${FS}bin${FS}java -fullversion 2>&1
+
+which ${MAKE} >${NULL} 2>&1
+if [ "$?" -ne '0' ]
+then
+    echo "No make found. Test passed."
+    exit 0
+fi
+
+which ${CC} >${NULL} 2>&1
+if [ "$?" -ne '0' ]
+then
+    echo "No C compiler found. Test passed."
+    exit 0
+fi
+case "$OS" in
+    SunOS )
+      ${CC} -v >${NULL} 2>&1
+      if [ "$?" -ne '0' ]
+      then
+          echo "No C compiler found. Test passed."
+          exit 0
+      fi
+esac
+
+cp ${TESTSRC}${FS}${MAKEFILE} .
+
+JAVA=${TESTJAVA}${FS}jre${FS}bin${FS}java
+JAVAC=${TESTJAVA}${FS}bin${FS}javac
+JAVAH=${TESTJAVA}${FS}bin${FS}javah
+
+export CC SYST ARCH LD_LIBRARY_PATH
+
+${JAVAC} -d . ${TESTSRC}${FS}MyCanvas.java
+${JAVAH} -jni -classpath . -d . MyCanvas
+${MAKE} -f ${MAKEFILE}
+${JAVA} -classpath . MyCanvas
+
+exit $?
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/JAWT/Makefile.cygwin	Mon Aug 19 16:40:38 2013 +0400
@@ -0,0 +1,49 @@
+# Copyright (c) 2013, 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.
+
+CFLAGS =	
+OBJS =		myfile.o
+HEADERS =	MyCanvas.h
+CLASSES =	MyCanvas.class
+
+JAVA =		$(TESTJAVA)/bin/java -classpath .
+JAVAC =		$(TESTJAVA)/bin/javac
+JAVAH =		$(TESTJAVA)/bin/javah
+DEL =		rm -rf
+LINK =		$(CC)
+
+INCLUDES =	-I $(TESTJAVA)/include/win32 -I $(TESTJAVA)/include -I .
+
+LIBS =		$(TESTJAVA)/lib/jawt.lib -lgdi32
+
+all:		$(CLASSES) mylib.dll
+
+mylib.dll: $(HEADERS) $(OBJS) 
+	$(LINK) -shared -o mylib.dll $(OBJS) $(LIBS) 
+
+myfile.o:
+	$(CC) $(CFLAGS)  $(INCLUDES) -c $(TESTSRC)/myfile.cpp
+
+clean:
+	$(DEL) mylib.* *.h *.class *.o
+ 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/JAWT/Makefile.unix	Mon Aug 19 16:40:38 2013 +0400
@@ -0,0 +1,48 @@
+# Copyright (c) 2013, 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.
+
+CFLAGS =	-fPIC -O
+OBJS =		myfile.o
+HEADERS =	MyCanvas.h
+CLASSES =	MyCanvas.class
+
+ENV =		/usr/bin/env
+JAVA =		$(TESTJAVA)/bin/java -classpath .
+JAVAC =		$(TESTJAVA)/bin/javac
+JAVAH =		$(TESTJAVA)/bin/javah
+LINK =		ld
+
+J_INC =		$(TESTJAVA)/include
+INCLUDES =	-I$(J_INC) -I$(J_INC)/$(SYST) -I.
+LIBS =		-L$(TESTJAVA)/jre/lib/$(ARCH) -ljawt -lX11
+
+all:		$(CLASSES) libmylib.so
+
+libmylib.so: $(HEADERS) $(OBJS) 
+	$(LINK) -G -o libmylib.so $(OBJS) $(LIBS)
+
+myfile.o:	$(TESTSRC)/myfile.c
+	$(CC)  $(CFLAGS) $(INCLUDES) -c $(TESTSRC)/myfile.c
+
+clean:
+	rm -rf libmylib.so $(HEADERS) $(CLASSES) $(OBJS)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/JAWT/Makefile.win	Mon Aug 19 16:40:38 2013 +0400
@@ -0,0 +1,47 @@
+# Copyright (c) 2013, 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.
+
+CFLAGS =	-nologo
+OBJS =		myfile.obj
+HEADERS =	MyCanvas.h
+CLASSES =	MyCanvas.class
+
+DEL =		del /Q
+LINK =		link
+
+INCLUDES =	-I$(TESTJAVA)\include\win32 -I$(TESTJAVA)\include
+
+LIBS =		gdi32.lib user32.lib $(TESTJAVA)\lib\jawt.lib
+
+all:		$(CLASSES) mylib.dll
+
+mylib.dll: $(HEADERS) $(OBJS) 
+	$(LINK) -nologo -dll -out:mylib.dll $(OBJS) $(LIBS)
+
+myfile.obj: $(TESTSRC)\myfile.cpp
+	$(CC) $(CFLAGS) $(INCLUDES) -c $(TESTSRC)\myfile.cpp
+
+clean:
+	$(DEL) mylib.* 
+	$(DEL) $(HEADERS) $(CLASSES)
+	$(DEL) *.obj
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/JAWT/MyCanvas.java	Mon Aug 19 16:40:38 2013 +0400
@@ -0,0 +1,72 @@
+/**
+ * Copyright (c) 2013, 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.
+ */
+
+import java.awt.*;
+import java.awt.event.*;
+
+public class MyCanvas extends Canvas {
+
+    static {
+        try {
+            System.loadLibrary("mylib");
+        } catch (Throwable t) {
+            System.out.println("Test failed!!");
+            t.printStackTrace();
+            System.exit(1);
+        }
+    }
+
+    public native void paint(Graphics g);
+
+    public static void main(String[] args) {
+        try {
+            Robot robot = new Robot();
+            Frame f = new Frame();
+            f.setBounds(0, 0, 100, 100);
+            f.add(new MyCanvas());
+            f.addWindowListener(new WindowAdapter() {
+                public void windowClosing(WindowEvent ev) {
+                    System.exit(0);
+                }
+            });
+            f.setVisible(true);
+            robot.delay(5000);
+            Color col1 = new Color(0, 0, 0);
+            Color col2 = robot.getPixelColor(f.getX()+50, f.getY()+50);
+            if (col1.equals(col2)) {
+                System.out.println("Test passed!");
+            } else {
+                throw new RuntimeException("Color of JAWT canvas is wrong or " +
+                        "it was not rendered. " + "Check that other windows " +
+                        "do not block the test frame.");
+            }
+            System.exit(0);
+        } catch (Throwable t) {
+            System.out.println("Test failed!");
+            t.printStackTrace();
+            System.exit(1);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/JAWT/myfile.c	Mon Aug 19 16:40:38 2013 +0400
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2013, 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.
+ */
+
+#include "MyCanvas.h"
+#include "jawt_md.h"
+
+/*
+ * Class:     MyCanvas
+ * Method:    paint
+ * Signature: (Ljava/awt/Graphics;)V
+ */
+JNIEXPORT void JNICALL Java_MyCanvas_paint
+(JNIEnv* env, jobject canvas, jobject graphics)
+{
+    JAWT awt;
+    JAWT_DrawingSurface* ds;
+    JAWT_DrawingSurfaceInfo* dsi;
+    JAWT_X11DrawingSurfaceInfo* dsi_x11;
+    jboolean result;
+    jint lock;
+    GC gc;
+    jobject ref;
+
+    /* Get the AWT */
+    awt.version = JAWT_VERSION_1_4;
+    if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
+        printf("AWT Not found\n");
+        return;
+    }
+
+    /* Lock the AWT */
+    awt.Lock(env);
+
+    /* Unlock the AWT */
+    awt.Unlock(env);
+
+    /* Get the drawing surface */
+    ds = awt.GetDrawingSurface(env, canvas);
+    if (ds == NULL) {
+        printf("NULL drawing surface\n");
+        return;
+    }
+
+    /* Lock the drawing surface */
+    lock = ds->Lock(ds);
+    printf("Lock value %d\n", (int)lock);
+    if((lock & JAWT_LOCK_ERROR) != 0) {
+        printf("Error locking surface\n");
+        awt.FreeDrawingSurface(ds);
+        return;
+    }
+
+    /* Get the drawing surface info */
+    dsi = ds->GetDrawingSurfaceInfo(ds);
+    if (dsi == NULL) {
+        printf("Error getting surface info\n");
+        ds->Unlock(ds);
+        awt.FreeDrawingSurface(ds);
+        return;
+    }
+
+    /* Get the platform-specific drawing info */
+    dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;
+
+    /* Now paint */
+    gc = XCreateGC(dsi_x11->display, dsi_x11->drawable, 0, 0);
+    XSetForeground(dsi_x11->display, gc, 0);
+    XFillRectangle(dsi_x11->display, dsi_x11->drawable, gc,
+                   5, 5, 90, 90);
+    XFreeGC(dsi_x11->display, gc);
+    ref = awt.GetComponent(env, (void*)(dsi_x11->drawable));
+    if (!(*env)->IsSameObject(env, ref, canvas)) {
+        printf("Error! Different objects!\n");
+    }
+
+    /* Free the drawing surface info */
+    ds->FreeDrawingSurfaceInfo(dsi);
+
+    /* Unlock the drawing surface */
+    ds->Unlock(ds);
+
+    /* Free the drawing surface */
+    awt.FreeDrawingSurface(ds);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/awt/JAWT/myfile.cpp	Mon Aug 19 16:40:38 2013 +0400
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2013, 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.
+ */
+
+#include <windows.h>
+#include "MyCanvas.h"
+#include "jawt_md.h"
+
+/*
+ * Class:     MyCanvas
+ * Method:    paint
+ * Signature: (Ljava/awt/Graphics;)V
+ */
+
+extern "C" {
+
+JNIEXPORT void JNICALL Java_MyCanvas_paint
+(JNIEnv* env, jobject canvas, jobject graphics)
+{
+    /* Get the AWT */
+    JAWT awt;
+    awt.version = JAWT_VERSION_1_4;
+    if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {
+        printf("AWT Not found\n");
+        return;
+    }
+
+    /* Lock the AWT */
+    awt.Lock(env);
+
+    /* Unlock the AWT */
+    awt.Unlock(env);
+
+    /* Get the drawing surface */
+    JAWT_DrawingSurface* ds = awt.GetDrawingSurface(env, canvas);
+    if (ds == NULL) {
+        printf("NULL drawing surface\n");
+        return;
+    }
+
+    /* Lock the drawing surface */
+    jint lock = ds->Lock(ds);
+    printf("Lock value %d\n", (int)lock);
+    if((lock & JAWT_LOCK_ERROR) != 0) {
+        printf("Error locking surface\n");
+        return;
+    }
+
+    /* Get the drawing surface info */
+    JAWT_DrawingSurfaceInfo* dsi = ds->GetDrawingSurfaceInfo(ds);
+    if (dsi == NULL) {
+        printf("Error getting surface info\n");
+        ds->Unlock(ds);
+        return;
+    }
+
+    /* Get the platform-specific drawing info */
+    JAWT_Win32DrawingSurfaceInfo* dsi_win =
+        (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
+
+    /* Now paint */
+    PAINTSTRUCT ps;
+    /* Do not use the HDC returned from BeginPaint()!! */
+    ::BeginPaint(dsi_win->hwnd, &ps);
+    HBRUSH hbrush = (HBRUSH)::GetStockObject(BLACK_BRUSH);
+    RECT rect;
+    rect.left = 5;
+    rect.top = 5;
+    rect.right = 95;
+    rect.bottom = 95;
+    ::FillRect(dsi_win->hdc, &rect, hbrush);
+    ::EndPaint(dsi_win->hwnd, &ps);
+
+    jobject ref = awt.GetComponent(env, (void*)(dsi_win->hwnd));
+    if (!env->IsSameObject(ref, canvas)) {
+        printf("Error! Different objects!\n");
+    }
+
+    /* Free the drawing surface info */
+    ds->FreeDrawingSurfaceInfo(dsi);
+
+    /* Unlock the drawing surface */
+    ds->Unlock(ds);
+
+    /* Free the drawing surface */
+    awt.FreeDrawingSurface(ds);
+}
+
+}