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]

Re: Reminder: Illegal Package-Private Accesses in libgcj


Bryce McKinlay wrote:
> So, is the problem:
> 
> a) there is/was a bug in the unwinder that causes it to try and throw 
> into OS frames even though you have an enclosing try block, or
> b) common C++ code on windows expects to be able to throw through the 
> OS ?

The problem is that, AFAICT, DW2 based EH
can't unwind through call frames that were not
generated with a corresponding EH DW2 CFI (Call
Frame Information). It's not Win32 specific
and should be visible on any system supported
by GCC that uses DW2 based exceptions. For example,
if the intermediate code was compiled using
"-fno-exceptions".

SJLJ, of course, does not have this problem. It
seems that the Microsoft Visual C/C++ and Borland
compilers have used this mechanism and therefore code
like following has come into existence that does
not have any problems when compiled with these
compilers but which abort when compiled with GCC+DW2:
-------------------------- 8< -----------------------------
  /* Register a window class with the given callback
     function WndProc( ). This function will be called
     when GUI events are received by the application
     window. */

  WNDCLASS WndClass;
  memset(&WndClass, 0, sizeof(WndClass));
  WndClass.hInstance = hInstance;
  WndClass.lpfnWndProc = WndProc;
  WndClass.lpszClassName = "Tutorial";
  WndClass.style = CS_HREDRAW | CS_VREDRAW;
  if(!RegisterClass(&WndClass))
    return 0;

  [...]

  /* Get into the GUI events message loop - DispatchMessage( )
     (a Win32 API function) will ultimately call our registered
     callback WndProc( ) */
  try {
    while(GetMessage(&Message, hWnd, 0, 0))
    {
      TranslateMessage(&Message);
      DispatchMessage(&Message);
    }
  }
  catch(...) {
    MessageBox(0, "Exception", "Exception", MB_OK);
  }


LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
  switch(iMessage)
  {
  case WM_CLOSE:
  case WM_DESTROY:
    /* Throw an exception */
    throw 10;
  default:
    return DefWindowProc(hWnd, iMessage, wParam, lParam);
  }
  return 0;
}
-------------------------- 8< -----------------------------

I don't like SJLJ much and think DWARF-2 is far
superior, especially when considered in the context
of normal Java programs that have tonnes of try/catch
blocks.

However, "legacy" code like the above do not let
MinGW use DW2 instead of SJLJ. People considering
moving from (say) MSVC or BCC to GCC (and who have
such code) do not particularly like it when
code that "obviously works" aborts with GCC.

Ranjit.

-- 
Ranjit Mathew          Email: rmathew AT hotmail DOT com

Bangalore, INDIA.      Web: http://ranjitmathew.tripod.com/


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