• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..30-Oct-2021-

CmdIDList.cppH A D30-Oct-20214 KiB12470

CmdIDList.hH A D30-Oct-20212.2 KiB6524

ComCtl32Util.cppH A D30-Oct-20213.2 KiB8449

ComCtl32Util.hH A D30-Oct-20212.4 KiB6627

Devices.cppH A D30-Oct-202113.4 KiB402190

Devices.hH A D30-Oct-20212.7 KiB7837

DllUtil.cppH A D30-Oct-20212.6 KiB8751

DllUtil.hH A D30-Oct-20213.2 KiB9849

GDIHashtable.cppH A D30-Oct-20214 KiB13988

GDIHashtable.hH A D30-Oct-20217.2 KiB20659

Hashtable.cppH A D30-Oct-20216.3 KiB233180

Hashtable.hH A D30-Oct-20214.7 KiB18663

MouseInfo.cppH A D30-Oct-20213.9 KiB12166

ObjectList.cppH A D30-Oct-20213.6 KiB12170

ObjectList.hH A D30-Oct-20211.8 KiB6328

README.JNIH A D30-Oct-20214.5 KiB134109

ShellFolder2.cppH A D30-Oct-202152.2 KiB1,5821,128

ThemeReader.cppH A D30-Oct-202129 KiB872612

WPrinterJob.cppH A D30-Oct-202137.1 KiB1,208916

alloc.hH A D30-Oct-20217.3 KiB208110

awt.hH A D30-Oct-202114.3 KiB389269

awt.rcH A D30-Oct-20212.9 KiB8475

awt_AWTEvent.cppH A D30-Oct-20213.6 KiB12360

awt_AWTEvent.hH A D30-Oct-20211.7 KiB4713

awt_BitmapUtil.cppH A D30-Oct-202112.2 KiB394273

awt_BitmapUtil.hH A D30-Oct-20213.1 KiB7714

awt_Brush.cppH A D30-Oct-20212.7 KiB8440

awt_Brush.hH A D30-Oct-20212.1 KiB6216

awt_Button.cppH A D30-Oct-202111.1 KiB406256

awt_Button.hH A D30-Oct-20212.3 KiB7024

awt_Canvas.cppH A D30-Oct-20218.3 KiB271173

awt_Canvas.hH A D30-Oct-20211.9 KiB5920

awt_Checkbox.cppH A D30-Oct-202118.5 KiB686464

awt_Checkbox.hH A D30-Oct-20212.8 KiB9034

awt_Choice.cppH A D30-Oct-202125.9 KiB900590

awt_Choice.hH A D30-Oct-20213.3 KiB10247

awt_Clipboard.cppH A D30-Oct-202115.2 KiB502342

awt_Clipboard.hH A D30-Oct-20212.4 KiB6728

awt_Color.cppH A D30-Oct-20211.8 KiB6013

awt_Color.hH A D30-Oct-20211.4 KiB398

awt_Component.cppH A D30-Oct-2021240.6 KiB7,4765,561

awt_Component.hH A D30-Oct-202132 KiB935579

awt_Container.cppH A D30-Oct-20211.8 KiB5413

awt_Container.hH A D30-Oct-20211.5 KiB459

awt_Cursor.cppH A D30-Oct-202117.2 KiB600430

awt_Cursor.hH A D30-Oct-20212.8 KiB9849

awt_CustomPaletteDef.hH A D30-Oct-202110.9 KiB275241

awt_DCHolder.cppH A D30-Oct-20213.1 KiB10769

awt_DCHolder.hH A D30-Oct-20212.1 KiB7340

awt_DataTransferer.cppH A D30-Oct-202130.7 KiB882638

awt_DataTransferer.hH A D30-Oct-202111.1 KiB180129

awt_Debug.cppH A D30-Oct-20217.2 KiB230148

awt_Debug.hH A D30-Oct-20213.4 KiB9140

awt_Desktop.cppH A D30-Oct-20215.6 KiB169100

awt_DesktopProperties.cppH A D30-Oct-202139.3 KiB1,008740

awt_DesktopProperties.hH A D30-Oct-20213.2 KiB8849

awt_Dialog.cppH A D30-Oct-202125.7 KiB846577

awt_Dialog.hH A D30-Oct-20215.1 KiB14059

awt_Dimension.cppH A D30-Oct-20211.9 KiB5716

awt_Dimension.hH A D30-Oct-20211.5 KiB4710

awt_DnDDS.cppH A D30-Oct-202146.7 KiB1,8001,198

awt_DnDDS.hH A D30-Oct-20219.7 KiB284154

awt_DnDDT.cppH A D30-Oct-202146.3 KiB1,6371,116

awt_DnDDT.hH A D30-Oct-20218.7 KiB273160

awt_DrawingSurface.cppH A D30-Oct-20218 KiB319230

awt_DrawingSurface.hH A D30-Oct-20215.4 KiB18090

awt_Event.cppH A D30-Oct-20212 KiB6321

awt_Event.hH A D30-Oct-20211.5 KiB4811

awt_FileDialog.cppH A D30-Oct-202123.6 KiB703499

awt_FileDialog.hH A D30-Oct-20212.5 KiB7633

awt_Font.cppH A D30-Oct-202155.4 KiB1,9361,445

awt_Font.hH A D30-Oct-20219.4 KiB299138

awt_Frame.cppH A D30-Oct-202162.3 KiB1,9771,411

awt_Frame.hH A D30-Oct-20217.8 KiB233105

awt_GDIObject.cppH A D30-Oct-20216.3 KiB16369

awt_GDIObject.hH A D30-Oct-20213.5 KiB11250

awt_IconCursor.cppH A D30-Oct-20213.2 KiB9859

awt_IconCursor.hH A D30-Oct-20211.5 KiB4110

awt_InputEvent.cppH A D30-Oct-20211.7 KiB4910

awt_InputEvent.hH A D30-Oct-20211.5 KiB459

awt_InputMethod.cppH A D30-Oct-202120.1 KiB637348

awt_InputTextInfor.cppH A D30-Oct-202115.4 KiB458305

awt_InputTextInfor.hH A D30-Oct-20213.2 KiB8634

awt_Insets.cppH A D30-Oct-20212.2 KiB6825

awt_Insets.hH A D30-Oct-20211.6 KiB4812

awt_KeyEvent.cppH A D30-Oct-20212.8 KiB7833

awt_KeyEvent.hH A D30-Oct-20211.7 KiB4914

awt_KeyboardFocusManager.cppH A D30-Oct-20213.1 KiB10847

awt_Label.cppH A D30-Oct-202111 KiB421260

awt_Label.hH A D30-Oct-20212.4 KiB8225

awt_List.cppH A D30-Oct-202127.7 KiB1,028700

awt_List.hH A D30-Oct-20216.5 KiB212135

awt_Menu.cppH A D30-Oct-202112.5 KiB480325

awt_Menu.hH A D30-Oct-20213.3 KiB10652

awt_MenuBar.cppH A D30-Oct-20219.1 KiB361224

awt_MenuBar.hH A D30-Oct-20212.6 KiB8636

awt_MenuItem.cppH A D30-Oct-202133.2 KiB1,164794

awt_MenuItem.hH A D30-Oct-20215.8 KiB191107

awt_Mlib.cppH A D30-Oct-20213.6 KiB10960

awt_Mlib.hH A D30-Oct-20211.7 KiB4916

awt_MouseEvent.cppH A D30-Oct-20212.3 KiB6926

awt_MouseEvent.hH A D30-Oct-20211.6 KiB4812

awt_Object.cppH A D30-Oct-20218.5 KiB265167

awt_Object.hH A D30-Oct-20214.6 KiB14368

awt_Palette.cppH A D30-Oct-202111.4 KiB381247

awt_Palette.hH A D30-Oct-20214.5 KiB11136

awt_Panel.cppH A D30-Oct-20211.8 KiB5614

awt_Panel.hH A D30-Oct-20211.5 KiB439

awt_Pen.cppH A D30-Oct-20212.7 KiB8541

awt_Pen.hH A D30-Oct-20212 KiB6216

awt_PopupMenu.cppH A D30-Oct-20219 KiB309206

awt_PopupMenu.hH A D30-Oct-20212.3 KiB7127

awt_PrintControl.cppH A D30-Oct-202141.5 KiB1,149853

awt_PrintControl.hH A D30-Oct-20215.1 KiB13687

awt_PrintDialog.cppH A D30-Oct-202110.5 KiB329230

awt_PrintDialog.hH A D30-Oct-20211.8 KiB5316

awt_PrintJob.cppH A D30-Oct-2021147.5 KiB4,5102,885

awt_Rectangle.cppH A D30-Oct-20212.3 KiB6825

awt_Rectangle.hH A D30-Oct-20211.6 KiB4812

awt_Robot.cppH A D30-Oct-202112.5 KiB405275

awt_Robot.hH A D30-Oct-20212 KiB5925

awt_ScrollPane.cppH A D30-Oct-202124 KiB813569

awt_ScrollPane.hH A D30-Oct-20213.2 KiB10041

awt_Scrollbar.cppH A D30-Oct-202119.8 KiB663413

awt_Scrollbar.hH A D30-Oct-20213.7 KiB11652

awt_Taskbar.cppH A D30-Oct-20214.2 KiB13673

awt_Taskbar.hH A D30-Oct-20214.2 KiB10966

awt_TextArea.cppH A D30-Oct-202116.4 KiB542325

awt_TextArea.hH A D30-Oct-20212.6 KiB8634

awt_TextComponent.cppH A D30-Oct-202135.8 KiB1,234793

awt_TextComponent.hH A D30-Oct-20216.7 KiB20196

awt_TextField.cppH A D30-Oct-20219 KiB292159

awt_TextField.hH A D30-Oct-20212 KiB6520

awt_Toolkit.cppH A D30-Oct-202199.6 KiB3,2472,219

awt_Toolkit.hH A D30-Oct-202124 KiB732423

awt_TrayIcon.cppH A D30-Oct-202132.7 KiB1,097816

awt_TrayIcon.hH A D30-Oct-20215.2 KiB15984

awt_Win32GraphicsConfig.cppH A D30-Oct-20214.2 KiB13063

awt_Win32GraphicsConfig.hH A D30-Oct-20211.4 KiB388

awt_Win32GraphicsDevice.cppH A D30-Oct-202145.6 KiB1,445990

awt_Win32GraphicsDevice.hH A D30-Oct-20215.6 KiB12691

awt_Win32GraphicsEnv.cppH A D30-Oct-202110.4 KiB347217

awt_Window.cppH A D30-Oct-2021116.3 KiB4,0422,897

awt_Window.hH A D30-Oct-202115.3 KiB430283

awt_new.cppH A D30-Oct-20217.1 KiB246149

awt_new.hH A D30-Oct-20211.6 KiB4811

awt_ole.cppH A D30-Oct-20213.2 KiB8754

awt_ole.hH A D30-Oct-20215.3 KiB195136

awtmsg.hH A D30-Oct-20217.2 KiB270175

colordata.hH A D30-Oct-20211.5 KiB4213

img_util_md.hH A D30-Oct-20213.9 KiB11666

initIDs.cppH A D30-Oct-20212.3 KiB8620

mlib_types_md.hH A D30-Oct-20211.3 KiB335

stdhdrs.hH A D30-Oct-20211.8 KiB5518

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