This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gcj, gdb warnings & jni method signatures


Hi,

As I've stated in previous messages I experience strange crashes and
gdb warnings in my SWT app compiled with gcj. When run under gdb, I
will receive between 3 and 5 warning messages like the following at very
specific points in the app:

warning: Invalid Address specified to RtlFreeHeap( 00240000, 0022F800 )

But 'c'ontinuing will work and the app keeps going. Under gdb the app
will always continue and work.

When the app isn't being run under gdb, there is a point at which the
app will (sometimes) crash (unpredictability is wonderful, isn't it?)
but the timing of the crash correlates to a point at which, under gdb,
it would have output one of those warnings.

So I've been trying to investigate the warnings a little further.
Maybe they relate to the point at which it crashes, and maybe they
don't, but they are interesting all the same.

I am using win32 (XP).
gcj (GCC) 4.0.0 20040914 (experimental)
GNU gdb 6.2.1 (with addr2line in path)

I wrote a simple test app that still accesses the swt.dll file for
native calls but accesses one of the native calls that always causes
the warning above. Note: It only causes the warning the first time
this native call is made; subsequent calls to the same native method
do not cause the warning.

I run the test app under gdb:
---
Starting program: /cygdrive/e/dev/wb/ostest.exe
Start
ThreadID: 4068
Start: org.eclipse.swt.internal.win32.LOGFONTW@fd7d48
warning: HEAP[ostest.exe]:
warning: Invalid Address specified to RtlFreeHeap( 00240000, 0022F800 )


Program received signal SIGTRAP, Trace/breakpoint trap.
0x77f767ce in ntdll!DbgUiConnectToDbg () from ntdll.dll
(gdb) bt
#0  0x77f767ce in ntdll!DbgUiConnectToDbg () from ntdll.dll
#1  0x77fa2612 in ntdll!RtlpNtMakeTemporaryKey () from ntdll.dll
#2  0x77f881c0 in ntdll!RtlCheckRegistryKey () from ntdll.dll
#3  0x00240000 in ?? ()
#4  0x0022f800 in ?? ()
#5  0x0022f6a4 in ?? ()
#6  0x77fa2f17 in ntdll!RtlpNtMakeTemporaryKey () from ntdll.dll
#7  0x00240000 in ?? ()
#8  0x0022f7f8 in ?? ()
#9  0x77fb1bd4 in wcstombs () from ntdll.dll
Previous frame inner to this frame (corrupt stack?)
(gdb) c
Continuing.
stupid
End1: 1
stupid
End2: 1

Program exited normally.
---
Thanks so much gdb.. anyway..

The first native call didn't cause any warning:

public static final native int GetCurrentThreadId ();

The call causing the warning is:

public static final native int CreateFontIndirectW (LOGFONTW lplf);

CreateFontIndirectW(new LOGFONTW());

So, I look it up in the swt.dll's source, and see the signature is:

JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_win32_OS_CreateFontIndirectW__Lorg_eclipse_swt_internal_win32_LOGFONTW_2
{ fprintf "stupid"; return 1 }...

But, for fun, I change it to:

JNIEXPORT jint JNICALL Java_org_eclipse_swt_internal_win32_OS_CreateFontIndirectW

recompile the .dll and re-run the app under gdb.  No more warning!

---
(gdb) r
Starting program: /cygdrive/e/dev/wb/ostest.exe
Start
ThreadID: 1788
Start: org.eclipse.swt.internal.win32.LOGFONTW@fd7d48
stupid
End1: 1
stupid
End2: 1

Program exited normally.
---

The only other method with the same name is CreateFontIndirectW__I so
there is no jobject argument conflict.

So, what is going on here? I've tried to make a stand-alone test app
but of course I can't duplicate the problem (even with a bunch of
same-name methods with different fully qualified classes as
signatures).

Here is the swt.dll with source: ftp://download.eclipse.org/R-3.0-200406251208/swt-3.0-win32.zip
And attached is my small console test app to call the native methods.

gcj -fjni --main=org.eclipse.swt.internal.win32.OS OS.java LOGFONT.java LOGFONTW.java -o ostest.exe

How can I find the real cause of this warning (if this is indeed a
problem)?

package org.eclipse.swt.internal.win32;

class OS {

	public static final int LF_FACESIZE = 32;
	public static final native int CreateFontIndirectW (LOGFONTW lplf);
	public static final native int GetCurrentThreadId ();

  static {
		try {
    	System.loadLibrary("swt-win32-3062");
		} catch (Exception e) {
			e.printStackTrace();
		}
  }

  public static void main(String[] args) {
		System.out.println("Start ");
		int id = GetCurrentThreadId ();
		System.out.println("ThreadID: " + id);
		LOGFONTW lfw = new LOGFONTW();
		System.out.println("Start: " + lfw);
 		int rc = CreateFontIndirectW(lfw);
		System.out.println("End1: " + rc);
 		rc = CreateFontIndirectW(lfw);
		System.out.println("End2: " + rc);

	}

}

package org.eclipse.swt.internal.win32;

public abstract class LOGFONT {
	public int lfHeight;    
	public int lfWidth;    
	public int lfEscapement; 
	public int lfOrientation;    
	public int lfWeight;    
	public byte lfItalic;    
	public byte lfUnderline; 
	public byte lfStrikeOut;    
	public byte lfCharSet;    
	public byte lfOutPrecision; 
	public byte lfClipPrecision;    
	public byte lfQuality;    
	public byte lfPitchAndFamily;
	public static final int sizeof = 92 	;
}
package org.eclipse.swt.internal.win32;

public class LOGFONTW extends LOGFONT {
					public char[] lfFaceName = new char[OS.LF_FACESIZE];
					public static final int sizeof = 92;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]