NameDateSize

..12-Dec-20174

alloc.hH A D12-Dec-20177.4 KiB

awt.hH A D12-Dec-201713.8 KiB

awt.rcH A D12-Dec-20172.9 KiB

awt_AWTEvent.cppH A D12-Dec-20173.6 KiB

awt_AWTEvent.hH A D12-Dec-20171.7 KiB

awt_BitmapUtil.cppH A D12-Dec-201711.9 KiB

awt_BitmapUtil.hH A D12-Dec-20173.1 KiB

awt_Brush.cppH A D12-Dec-20172.7 KiB

awt_Brush.hH A D12-Dec-20172.1 KiB

awt_Button.cppH A D12-Dec-201711.3 KiB

awt_Button.hH A D12-Dec-20172.3 KiB

awt_Canvas.cppH A D12-Dec-20178.4 KiB

awt_Canvas.hH A D12-Dec-20171.9 KiB

awt_Checkbox.cppH A D12-Dec-201718.6 KiB

awt_Checkbox.hH A D12-Dec-20172.8 KiB

awt_Choice.cppH A D12-Dec-201726 KiB

awt_Choice.hH A D12-Dec-20173.3 KiB

awt_Clipboard.cppH A D12-Dec-201715.2 KiB

awt_Clipboard.hH A D12-Dec-20172.4 KiB

awt_Color.cppH A D12-Dec-20173.4 KiB

awt_Color.hH A D12-Dec-20171.4 KiB

awt_Component.cppH A D12-Dec-2017237.1 KiB

awt_Component.hH A D12-Dec-201731.5 KiB

awt_Container.cppH A D12-Dec-20171.8 KiB

awt_Container.hH A D12-Dec-20171.5 KiB

awt_Cursor.cppH A D12-Dec-201717.2 KiB

awt_Cursor.hH A D12-Dec-20172.8 KiB

awt_CustomPaletteDef.hH A D12-Dec-201710.9 KiB

awt_DataTransferer.cppH A D12-Dec-201730.7 KiB

awt_DataTransferer.hH A D12-Dec-201711.1 KiB

awt_DCHolder.cppH A D12-Dec-20173.1 KiB

awt_DCHolder.hH A D12-Dec-20172.1 KiB

awt_Debug.cppH A D12-Dec-20177.1 KiB

awt_Debug.hH A D12-Dec-20173.6 KiB

awt_Desktop.cppH A D12-Dec-20175.5 KiB

awt_DesktopProperties.cppH A D12-Dec-201739.3 KiB

awt_DesktopProperties.hH A D12-Dec-20173.2 KiB

awt_Dialog.cppH A D12-Dec-201725.7 KiB

awt_Dialog.hH A D12-Dec-20175.1 KiB

awt_Dimension.cppH A D12-Dec-20171.9 KiB

awt_Dimension.hH A D12-Dec-20171.5 KiB

awt_DnDDS.cppH A D12-Dec-201746.3 KiB

awt_DnDDS.hH A D12-Dec-20179.7 KiB

awt_DnDDT.cppH A D12-Dec-201745.9 KiB

awt_DnDDT.hH A D12-Dec-20178.7 KiB

awt_DrawingSurface.cppH A D12-Dec-20178 KiB

awt_DrawingSurface.hH A D12-Dec-20175.4 KiB

awt_Event.cppH A D12-Dec-20172 KiB

awt_Event.hH A D12-Dec-20171.5 KiB

awt_FileDialog.cppH A D12-Dec-201724 KiB

awt_FileDialog.hH A D12-Dec-20172.5 KiB

awt_Font.cppH A D12-Dec-201755.2 KiB

awt_Font.hH A D12-Dec-20179.4 KiB

awt_Frame.cppH A D12-Dec-201762.8 KiB

awt_Frame.hH A D12-Dec-20177.8 KiB

awt_GDIObject.cppH A D12-Dec-20176.3 KiB

awt_GDIObject.hH A D12-Dec-20173.5 KiB

awt_IconCursor.cppH A D12-Dec-20173.2 KiB

awt_IconCursor.hH A D12-Dec-20171.5 KiB

awt_InputEvent.cppH A D12-Dec-20171.7 KiB

awt_InputEvent.hH A D12-Dec-20171.5 KiB

awt_InputMethod.cppH A D12-Dec-201719.5 KiB

awt_InputTextInfor.cppH A D12-Dec-201714.9 KiB

awt_InputTextInfor.hH A D12-Dec-20173.2 KiB

awt_Insets.cppH A D12-Dec-20172.2 KiB

awt_Insets.hH A D12-Dec-20171.6 KiB

awt_KeyboardFocusManager.cppH A D12-Dec-20173.1 KiB

awt_KeyEvent.cppH A D12-Dec-20172.8 KiB

awt_KeyEvent.hH A D12-Dec-20171.7 KiB

awt_Label.cppH A D12-Dec-201711.1 KiB

awt_Label.hH A D12-Dec-20172.4 KiB

awt_List.cppH A D12-Dec-201727.7 KiB

awt_List.hH A D12-Dec-20176.5 KiB

awt_Menu.cppH A D12-Dec-201712.5 KiB

awt_Menu.hH A D12-Dec-20173.3 KiB

awt_MenuBar.cppH A D12-Dec-20179 KiB

awt_MenuBar.hH A D12-Dec-20172.6 KiB

awt_MenuItem.cppH A D12-Dec-201733.1 KiB

awt_MenuItem.hH A D12-Dec-20175.8 KiB

awt_Mlib.cppH A D12-Dec-20173.6 KiB

awt_Mlib.hH A D12-Dec-20171.7 KiB

awt_MouseEvent.cppH A D12-Dec-20172.1 KiB

awt_MouseEvent.hH A D12-Dec-20171.6 KiB

awt_new.cppH A D12-Dec-20177.1 KiB

awt_new.hH A D12-Dec-20171.6 KiB

awt_Object.cppH A D12-Dec-20178.5 KiB

awt_Object.hH A D12-Dec-20174.6 KiB

awt_ole.cppH A D12-Dec-20173.2 KiB

awt_ole.hH A D12-Dec-20175.3 KiB

awt_Palette.cppH A D12-Dec-201711.4 KiB

awt_Palette.hH A D12-Dec-20174.5 KiB

awt_Panel.cppH A D12-Dec-20171.8 KiB

awt_Panel.hH A D12-Dec-20171.5 KiB

awt_Pen.cppH A D12-Dec-20172.7 KiB

awt_Pen.hH A D12-Dec-20172 KiB

awt_PopupMenu.cppH A D12-Dec-20179 KiB

awt_PopupMenu.hH A D12-Dec-20172.3 KiB

awt_PrintControl.cppH A D12-Dec-201741.4 KiB

awt_PrintControl.hH A D12-Dec-20175.1 KiB

awt_PrintDialog.cppH A D12-Dec-201710.5 KiB

awt_PrintDialog.hH A D12-Dec-20171.8 KiB

awt_PrintJob.cppH A D12-Dec-2017144.8 KiB

awt_Rectangle.cppH A D12-Dec-20172.3 KiB

awt_Rectangle.hH A D12-Dec-20171.6 KiB

awt_Robot.cppH A D12-Dec-201714.2 KiB

awt_Robot.hH A D12-Dec-20172 KiB

awt_Scrollbar.cppH A D12-Dec-201718.6 KiB

awt_Scrollbar.hH A D12-Dec-20173.6 KiB

awt_ScrollPane.cppH A D12-Dec-201724 KiB

awt_ScrollPane.hH A D12-Dec-20173.2 KiB

awt_Taskbar.cppH A D12-Dec-20174.2 KiB

awt_Taskbar.hH A D12-Dec-20174.2 KiB

awt_TextArea.cppH A D12-Dec-201716.5 KiB

awt_TextArea.hH A D12-Dec-20172.6 KiB

awt_TextComponent.cppH A D12-Dec-201735.8 KiB

awt_TextComponent.hH A D12-Dec-20176.7 KiB

awt_TextField.cppH A D12-Dec-20179.1 KiB

awt_TextField.hH A D12-Dec-20172 KiB

awt_Toolkit.cppH A D12-Dec-201784.3 KiB

awt_Toolkit.hH A D12-Dec-201721.7 KiB

awt_TrayIcon.cppH A D12-Dec-201732.5 KiB

awt_TrayIcon.hH A D12-Dec-20175.2 KiB

awt_Win32GraphicsConfig.cppH A D12-Dec-20174.2 KiB

awt_Win32GraphicsConfig.hH A D12-Dec-20171.4 KiB

awt_Win32GraphicsDevice.cppH A D12-Dec-201745.5 KiB

awt_Win32GraphicsDevice.hH A D12-Dec-20175.6 KiB

awt_Win32GraphicsEnv.cppH A D12-Dec-201710.4 KiB

awt_Window.cppH A D12-Dec-2017113.5 KiB

awt_Window.hH A D12-Dec-201714.8 KiB

awtmsg.hH A D12-Dec-20177.2 KiB

check.bmpH A D12-Dec-2017166

CmdIDList.cppH A D12-Dec-20174 KiB

CmdIDList.hH A D12-Dec-20172.1 KiB

colordata.hH A D12-Dec-20171.5 KiB

ComCtl32Util.cppH A D12-Dec-20173.2 KiB

ComCtl32Util.hH A D12-Dec-20172.4 KiB

Devices.cppH A D12-Dec-201713.4 KiB

Devices.hH A D12-Dec-20172.7 KiB

DllUtil.cppH A D12-Dec-20172.6 KiB

DllUtil.hH A D12-Dec-20173.2 KiB

GDIHashtable.cppH A D12-Dec-20174 KiB

GDIHashtable.hH A D12-Dec-20177.2 KiB

Hashtable.cppH A D12-Dec-20176.3 KiB

Hashtable.hH A D12-Dec-20174.7 KiB

img_util_md.hH A D12-Dec-20173.9 KiB

initIDs.cppH A D12-Dec-20172.3 KiB

mlib_types_md.hH A D12-Dec-20171.3 KiB

MouseInfo.cppH A D12-Dec-20173.9 KiB

ObjectList.cppH A D12-Dec-20173.6 KiB

ObjectList.hH A D12-Dec-20171.8 KiB

README.JNIH A D12-Dec-20174.5 KiB

security_warning.icoH A D12-Dec-201717.1 KiB

security_warning_bw.icoH A D12-Dec-201717.1 KiB

security_warning_int.icoH A D12-Dec-201717.1 KiB

ShellFolder2.cppH A D12-Dec-201750.4 KiB

stdhdrs.hH A D12-Dec-20171.8 KiB

ThemeReader.cppH A D12-Dec-201729 KiB

WPrinterJob.cppH A D12-Dec-201735.5 KiB

README.JNI

1[sl@eng 97/07/24]
2
3All the free-standing functions (those that are not JNI native
4methods) must not leak local references.  Local references are
5automatically freed when the native method returns to Java. However,
6the free-standing functions are called from the event loop that never
7returns to Java. If these functions do not clean up the local
8references they create, the Java objects corresponding to the local
9references will never be garbage collected.
10
11This is caused by the fact that JNI does not clean up local refs 
12until control returns to Java. However, this problem is somewhat
13unique to AWT code because AWT code has long-running native methods
14that never return.
15
16Local refs may be cleaned up manually *before* control returns to 
17Java in one of the following two ways:
18
191. Use EnsureLocalCapacity at the beginning of the function to make
20sure the VM has enough memory to create the number of JNI local refs
21needed in the function. Use DeleteLocalRef to clean up any local ref
22created inside the function that are not returned as the result. For
23example:
24
25  void AwtComponent::MeasureListItem(JNIEnv *env, 
26				     MEASUREITEMSTRUCT far& measureInfo)
27  {
28      if (env->EnsureLocalCapacity(1) < 0) {
29	  return;
30      }
31      jobject dimension = PreferredItemSize(env);
32
33      ... /* Use dimension */
34
35      env->DeleteLocalRef(dimension);
36  }
37
382. Use PushLocalFrame and PopLocalFrame to start a new local reference
39frame. All the local refs created in the new frame will be automatically
40freed when PopLocalFrame is called. For example, the above function can be
41rewritten as follows:
42
43  void AwtComponent::MeasureListItem(JNIEnv *env, 
44				     MEASUREITEMSTRUCT far& measureInfo)
45  {
46      if (env->PushLocalFrame(1) < 0) {
47	  return;
48      }
49      jobject dimension = PreferredItemSize(env);
50
51      ... /* Use dimension */
52
53      env->PopLocalFrame(NULL);
54  }
55
56The second approach is easier to use when there are multiple local refs 
57to manage. The first approach is more efficient when the function only 
58needs to create a small number (3 or less) of local refs.
59
60Pay special attention to local refs created inside a loop. They must be
61deleted after every iteration, otherwise they accumulate very quickly:
62
63int AwtFont::getFontDescriptorNumber(JNIEnv *env, jobject font,
64				     jobject fontDescriptor)
65{
66    ... /* other stuff */
67
68    jarray array = ...
69
70    for (i = 0; i < num; i++){
71	refFontDescriptor = env->GetObjectArrayElement(array, i);
72	if (env->IsSameObject(refFontDescriptor, fontDescriptor)) {
73	    env->DeleteLocalRef(refFontDescriptor);
74	    env->DeleteLocalRef(array);
75	    return i;
76	}
77	env->DeleteLocalRef(refFontDescriptor);
78    }
79    env->DeleteLocalRef(array);
80    return 0;	// Not found.  Use default.
81}
82
83Note that we must make sure the local refs are cleaned up at every possible
84return branch. To reduce code duplication, many AWT functions use "goto"
85to jump to a common set of cleanup statements.
86
87Even if we use PushLocalFrame, we must still delete the local refs created
88in the loop:
89
90    if (env->PushLocalFrame(2) < 0)
91	return 0;
92    jarray array = ...
93    for (i = 0; i < num; i++){
94	refFontDescriptor = env->GetObjectArrayElement(array, i);
95	if (env->IsSameObject(refFontDescriptor, fontDescriptor)) {
96	    env->PopLocalFrame(NULL);
97	    return i;
98	}
99	env->DeleteLocalRef(refFontDescriptor);
100    }
101    env->PopLocalFrame(NULL);
102    return 0;	// Not found.  Use default.
103
104unless we ensure that we have space for all possible local refs we are 
105going to create inside the loop (note the different argument passed 
106to PushLocalFrame):
107
108// Maximum number of local refs we can create in this code segment is
109// num + 1.
110    if (env->PushLocalFrame(num + 1) < 0)
111	return 0;
112    jarray array = ...
113    for (i = 0; i < num; i++){
114	refFontDescriptor = env->GetObjectArrayElement(array, i);
115	if (env->IsSameObject(refFontDescriptor, fontDescriptor)) {
116	    env->PopLocalFrame(NULL);
117	    return i;
118	}
119// no longer necessary. env->DeleteLocalRef(refFontDescriptor);
120    }
121    env->PopLocalFrame(NULL);
122    return 0;	// Not found.  Use default.
123
124THINGS TO DO:
125
126    1. Investigate another possibility of dealing with local refs. Instead
127    of making sure every free-standing function does not leak local refs,
128    we could alternatively create a new local ref frame for each invocation
129    of callback functions. All local refs created during the execution of 
130    the callback will then be automatically freed.
131
132    2. Handle exceptions properly. The current code lacks error checking
133    and recovery. This leads to random runtime crashes.
134