bcd5b263654af2eb2336cd7f7f7c45cc08458287
[oota-llvm.git] / lib / ExecutionEngine / JIT / JITDwarfEmitter.cpp
1 //===----- JITDwarfEmitter.cpp - Write dwarf tables into memory -----------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a JITDwarfEmitter object that is used by the JIT to
11 // write dwarf tables to memory.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "JIT.h"
16 #include "JITDwarfEmitter.h"
17 #include "llvm/DerivedTypes.h"
18 #include "llvm/Function.h"
19 #include "llvm/GlobalVariable.h"
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/CodeGen/JITCodeEmitter.h"
22 #include "llvm/CodeGen/MachineFunction.h"
23 #include "llvm/CodeGen/MachineModuleInfo.h"
24 #include "llvm/ExecutionEngine/JITMemoryManager.h"
25 #include "llvm/MC/MachineLocation.h"
26 #include "llvm/MC/MCAsmInfo.h"
27 #include "llvm/MC/MCSymbol.h"
28 #include "llvm/Support/ErrorHandling.h"
29 #include "llvm/DataLayout.h"
30 #include "llvm/Target/TargetInstrInfo.h"
31 #include "llvm/Target/TargetFrameLowering.h"
32 #include "llvm/Target/TargetMachine.h"
33 #include "llvm/Target/TargetRegisterInfo.h"
34 using namespace llvm;
35
36 JITDwarfEmitter::JITDwarfEmitter(JIT& theJit) : MMI(0), Jit(theJit) {}
37
38
39 unsigned char* JITDwarfEmitter::EmitDwarfTable(MachineFunction& F,
40                                                JITCodeEmitter& jce,
41                                                unsigned char* StartFunction,
42                                                unsigned char* EndFunction,
43                                                unsigned char* &EHFramePtr) {
44   assert(MMI && "MachineModuleInfo not registered!");
45
46   const TargetMachine& TM = F.getTarget();
47   TD = TM.getDataLayout();
48   stackGrowthDirection = TM.getFrameLowering()->getStackGrowthDirection();
49   RI = TM.getRegisterInfo();
50   MAI = TM.getMCAsmInfo();
51   JCE = &jce;
52
53   unsigned char* ExceptionTable = EmitExceptionTable(&F, StartFunction,
54                                                      EndFunction);
55
56   unsigned char* Result = 0;
57
58   const std::vector<const Function *> Personalities = MMI->getPersonalities();
59   EHFramePtr = EmitCommonEHFrame(Personalities[MMI->getPersonalityIndex()]);
60
61   Result = EmitEHFrame(Personalities[MMI->getPersonalityIndex()], EHFramePtr,
62                        StartFunction, EndFunction, ExceptionTable);
63
64   return Result;
65 }
66
67
68 void
69 JITDwarfEmitter::EmitFrameMoves(intptr_t BaseLabelPtr,
70                                 const std::vector<MachineMove> &Moves) const {
71   unsigned PointerSize = TD->getPointerSize(0);
72   int stackGrowth = stackGrowthDirection == TargetFrameLowering::StackGrowsUp ?
73           PointerSize : -PointerSize;
74   MCSymbol *BaseLabel = 0;
75
76   for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
77     const MachineMove &Move = Moves[i];
78     MCSymbol *Label = Move.getLabel();
79
80     // Throw out move if the label is invalid.
81     if (Label && (*JCE->getLabelLocations())[Label] == 0)
82       continue;
83
84     intptr_t LabelPtr = 0;
85     if (Label) LabelPtr = JCE->getLabelAddress(Label);
86
87     const MachineLocation &Dst = Move.getDestination();
88     const MachineLocation &Src = Move.getSource();
89
90     // Advance row if new location.
91     if (BaseLabelPtr && Label && BaseLabel != Label) {
92       JCE->emitByte(dwarf::DW_CFA_advance_loc4);
93       JCE->emitInt32(LabelPtr - BaseLabelPtr);
94
95       BaseLabel = Label;
96       BaseLabelPtr = LabelPtr;
97     }
98
99     // If advancing cfa.
100     if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) {
101       if (!Src.isReg()) {
102         if (Src.getReg() == MachineLocation::VirtualFP) {
103           JCE->emitByte(dwarf::DW_CFA_def_cfa_offset);
104         } else {
105           JCE->emitByte(dwarf::DW_CFA_def_cfa);
106           JCE->emitULEB128Bytes(RI->getDwarfRegNum(Src.getReg(), true));
107         }
108
109         JCE->emitULEB128Bytes(-Src.getOffset());
110       } else {
111         llvm_unreachable("Machine move not supported yet.");
112       }
113     } else if (Src.isReg() &&
114       Src.getReg() == MachineLocation::VirtualFP) {
115       if (Dst.isReg()) {
116         JCE->emitByte(dwarf::DW_CFA_def_cfa_register);
117         JCE->emitULEB128Bytes(RI->getDwarfRegNum(Dst.getReg(), true));
118       } else {
119         llvm_unreachable("Machine move not supported yet.");
120       }
121     } else {
122       unsigned Reg = RI->getDwarfRegNum(Src.getReg(), true);
123       int Offset = Dst.getOffset() / stackGrowth;
124
125       if (Offset < 0) {
126         JCE->emitByte(dwarf::DW_CFA_offset_extended_sf);
127         JCE->emitULEB128Bytes(Reg);
128         JCE->emitSLEB128Bytes(Offset);
129       } else if (Reg < 64) {
130         JCE->emitByte(dwarf::DW_CFA_offset + Reg);
131         JCE->emitULEB128Bytes(Offset);
132       } else {
133         JCE->emitByte(dwarf::DW_CFA_offset_extended);
134         JCE->emitULEB128Bytes(Reg);
135         JCE->emitULEB128Bytes(Offset);
136       }
137     }
138   }
139 }
140
141 /// SharedTypeIds - How many leading type ids two landing pads have in common.
142 static unsigned SharedTypeIds(const LandingPadInfo *L,
143                               const LandingPadInfo *R) {
144   const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
145   unsigned LSize = LIds.size(), RSize = RIds.size();
146   unsigned MinSize = LSize < RSize ? LSize : RSize;
147   unsigned Count = 0;
148
149   for (; Count != MinSize; ++Count)
150     if (LIds[Count] != RIds[Count])
151       return Count;
152
153   return Count;
154 }
155
156
157 /// PadLT - Order landing pads lexicographically by type id.
158 static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R) {
159   const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
160   unsigned LSize = LIds.size(), RSize = RIds.size();
161   unsigned MinSize = LSize < RSize ? LSize : RSize;
162
163   for (unsigned i = 0; i != MinSize; ++i)
164     if (LIds[i] != RIds[i])
165       return LIds[i] < RIds[i];
166
167   return LSize < RSize;
168 }
169
170 namespace {
171
172 /// ActionEntry - Structure describing an entry in the actions table.
173 struct ActionEntry {
174   int ValueForTypeID; // The value to write - may not be equal to the type id.
175   int NextAction;
176   struct ActionEntry *Previous;
177 };
178
179 /// PadRange - Structure holding a try-range and the associated landing pad.
180 struct PadRange {
181   // The index of the landing pad.
182   unsigned PadIndex;
183   // The index of the begin and end labels in the landing pad's label lists.
184   unsigned RangeIndex;
185 };
186
187 typedef DenseMap<MCSymbol*, PadRange> RangeMapType;
188
189 /// CallSiteEntry - Structure describing an entry in the call-site table.
190 struct CallSiteEntry {
191   MCSymbol *BeginLabel; // zero indicates the start of the function.
192   MCSymbol *EndLabel;   // zero indicates the end of the function.
193   MCSymbol *PadLabel;   // zero indicates that there is no landing pad.
194   unsigned Action;
195 };
196
197 }
198
199 unsigned char* JITDwarfEmitter::EmitExceptionTable(MachineFunction* MF,
200                                          unsigned char* StartFunction,
201                                          unsigned char* EndFunction) const {
202   assert(MMI && "MachineModuleInfo not registered!");
203
204   // Map all labels and get rid of any dead landing pads.
205   MMI->TidyLandingPads(JCE->getLabelLocations());
206
207   const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
208   const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
209   const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads();
210   if (PadInfos.empty()) return 0;
211
212   // Sort the landing pads in order of their type ids.  This is used to fold
213   // duplicate actions.
214   SmallVector<const LandingPadInfo *, 64> LandingPads;
215   LandingPads.reserve(PadInfos.size());
216   for (unsigned i = 0, N = PadInfos.size(); i != N; ++i)
217     LandingPads.push_back(&PadInfos[i]);
218   std::sort(LandingPads.begin(), LandingPads.end(), PadLT);
219
220   // Negative type ids index into FilterIds, positive type ids index into
221   // TypeInfos.  The value written for a positive type id is just the type
222   // id itself.  For a negative type id, however, the value written is the
223   // (negative) byte offset of the corresponding FilterIds entry.  The byte
224   // offset is usually equal to the type id, because the FilterIds entries
225   // are written using a variable width encoding which outputs one byte per
226   // entry as long as the value written is not too large, but can differ.
227   // This kind of complication does not occur for positive type ids because
228   // type infos are output using a fixed width encoding.
229   // FilterOffsets[i] holds the byte offset corresponding to FilterIds[i].
230   SmallVector<int, 16> FilterOffsets;
231   FilterOffsets.reserve(FilterIds.size());
232   int Offset = -1;
233   for(std::vector<unsigned>::const_iterator I = FilterIds.begin(),
234     E = FilterIds.end(); I != E; ++I) {
235     FilterOffsets.push_back(Offset);
236     Offset -= MCAsmInfo::getULEB128Size(*I);
237   }
238
239   // Compute the actions table and gather the first action index for each
240   // landing pad site.
241   SmallVector<ActionEntry, 32> Actions;
242   SmallVector<unsigned, 64> FirstActions;
243   FirstActions.reserve(LandingPads.size());
244
245   int FirstAction = 0;
246   unsigned SizeActions = 0;
247   for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
248     const LandingPadInfo *LP = LandingPads[i];
249     const std::vector<int> &TypeIds = LP->TypeIds;
250     const unsigned NumShared = i ? SharedTypeIds(LP, LandingPads[i-1]) : 0;
251     unsigned SizeSiteActions = 0;
252
253     if (NumShared < TypeIds.size()) {
254       unsigned SizeAction = 0;
255       ActionEntry *PrevAction = 0;
256
257       if (NumShared) {
258         const unsigned SizePrevIds = LandingPads[i-1]->TypeIds.size();
259         assert(Actions.size());
260         PrevAction = &Actions.back();
261         SizeAction = MCAsmInfo::getSLEB128Size(PrevAction->NextAction) +
262           MCAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
263         for (unsigned j = NumShared; j != SizePrevIds; ++j) {
264           SizeAction -= MCAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
265           SizeAction += -PrevAction->NextAction;
266           PrevAction = PrevAction->Previous;
267         }
268       }
269
270       // Compute the actions.
271       for (unsigned I = NumShared, M = TypeIds.size(); I != M; ++I) {
272         int TypeID = TypeIds[I];
273         assert(-1-TypeID < (int)FilterOffsets.size() && "Unknown filter id!");
274         int ValueForTypeID = TypeID < 0 ? FilterOffsets[-1 - TypeID] : TypeID;
275         unsigned SizeTypeID = MCAsmInfo::getSLEB128Size(ValueForTypeID);
276
277         int NextAction = SizeAction ? -(SizeAction + SizeTypeID) : 0;
278         SizeAction = SizeTypeID + MCAsmInfo::getSLEB128Size(NextAction);
279         SizeSiteActions += SizeAction;
280
281         ActionEntry Action = {ValueForTypeID, NextAction, PrevAction};
282         Actions.push_back(Action);
283
284         PrevAction = &Actions.back();
285       }
286
287       // Record the first action of the landing pad site.
288       FirstAction = SizeActions + SizeSiteActions - SizeAction + 1;
289     } // else identical - re-use previous FirstAction
290
291     FirstActions.push_back(FirstAction);
292
293     // Compute this sites contribution to size.
294     SizeActions += SizeSiteActions;
295   }
296
297   // Compute the call-site table.  Entries must be ordered by address.
298   SmallVector<CallSiteEntry, 64> CallSites;
299
300   RangeMapType PadMap;
301   for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
302     const LandingPadInfo *LandingPad = LandingPads[i];
303     for (unsigned j=0, E = LandingPad->BeginLabels.size(); j != E; ++j) {
304       MCSymbol *BeginLabel = LandingPad->BeginLabels[j];
305       assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!");
306       PadRange P = { i, j };
307       PadMap[BeginLabel] = P;
308     }
309   }
310
311   bool MayThrow = false;
312   MCSymbol *LastLabel = 0;
313   for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
314         I != E; ++I) {
315     for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end();
316           MI != E; ++MI) {
317       if (!MI->isLabel()) {
318         MayThrow |= MI->isCall();
319         continue;
320       }
321
322       MCSymbol *BeginLabel = MI->getOperand(0).getMCSymbol();
323       assert(BeginLabel && "Invalid label!");
324
325       if (BeginLabel == LastLabel)
326         MayThrow = false;
327
328       RangeMapType::iterator L = PadMap.find(BeginLabel);
329
330       if (L == PadMap.end())
331         continue;
332
333       PadRange P = L->second;
334       const LandingPadInfo *LandingPad = LandingPads[P.PadIndex];
335
336       assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] &&
337               "Inconsistent landing pad map!");
338
339       // If some instruction between the previous try-range and this one may
340       // throw, create a call-site entry with no landing pad for the region
341       // between the try-ranges.
342       if (MayThrow) {
343         CallSiteEntry Site = {LastLabel, BeginLabel, 0, 0};
344         CallSites.push_back(Site);
345       }
346
347       LastLabel = LandingPad->EndLabels[P.RangeIndex];
348       CallSiteEntry Site = {BeginLabel, LastLabel,
349         LandingPad->LandingPadLabel, FirstActions[P.PadIndex]};
350
351       assert(Site.BeginLabel && Site.EndLabel && Site.PadLabel &&
352               "Invalid landing pad!");
353
354       // Try to merge with the previous call-site.
355       if (CallSites.size()) {
356         CallSiteEntry &Prev = CallSites.back();
357         if (Site.PadLabel == Prev.PadLabel && Site.Action == Prev.Action) {
358           // Extend the range of the previous entry.
359           Prev.EndLabel = Site.EndLabel;
360           continue;
361         }
362       }
363
364       // Otherwise, create a new call-site.
365       CallSites.push_back(Site);
366     }
367   }
368   // If some instruction between the previous try-range and the end of the
369   // function may throw, create a call-site entry with no landing pad for the
370   // region following the try-range.
371   if (MayThrow) {
372     CallSiteEntry Site = {LastLabel, 0, 0, 0};
373     CallSites.push_back(Site);
374   }
375
376   // Final tallies.
377   unsigned SizeSites = CallSites.size() * (sizeof(int32_t) + // Site start.
378                                             sizeof(int32_t) + // Site length.
379                                             sizeof(int32_t)); // Landing pad.
380   for (unsigned i = 0, e = CallSites.size(); i < e; ++i)
381     SizeSites += MCAsmInfo::getULEB128Size(CallSites[i].Action);
382
383   unsigned SizeTypes = TypeInfos.size() * TD->getPointerSize(0);
384
385   unsigned TypeOffset = sizeof(int8_t) + // Call site format
386                         // Call-site table length
387                         MCAsmInfo::getULEB128Size(SizeSites) +
388                         SizeSites + SizeActions + SizeTypes;
389
390   // Begin the exception table.
391   JCE->emitAlignmentWithFill(4, 0);
392   // Asm->EOL("Padding");
393
394   unsigned char* DwarfExceptionTable = (unsigned char*)JCE->getCurrentPCValue();
395
396   // Emit the header.
397   JCE->emitByte(dwarf::DW_EH_PE_omit);
398   // Asm->EOL("LPStart format (DW_EH_PE_omit)");
399   JCE->emitByte(dwarf::DW_EH_PE_absptr);
400   // Asm->EOL("TType format (DW_EH_PE_absptr)");
401   JCE->emitULEB128Bytes(TypeOffset);
402   // Asm->EOL("TType base offset");
403   JCE->emitByte(dwarf::DW_EH_PE_udata4);
404   // Asm->EOL("Call site format (DW_EH_PE_udata4)");
405   JCE->emitULEB128Bytes(SizeSites);
406   // Asm->EOL("Call-site table length");
407
408   // Emit the landing pad site information.
409   for (unsigned i = 0; i < CallSites.size(); ++i) {
410     CallSiteEntry &S = CallSites[i];
411     intptr_t BeginLabelPtr = 0;
412     intptr_t EndLabelPtr = 0;
413
414     if (!S.BeginLabel) {
415       BeginLabelPtr = (intptr_t)StartFunction;
416       JCE->emitInt32(0);
417     } else {
418       BeginLabelPtr = JCE->getLabelAddress(S.BeginLabel);
419       JCE->emitInt32(BeginLabelPtr - (intptr_t)StartFunction);
420     }
421
422     // Asm->EOL("Region start");
423
424     if (!S.EndLabel)
425       EndLabelPtr = (intptr_t)EndFunction;
426     else
427       EndLabelPtr = JCE->getLabelAddress(S.EndLabel);
428
429     JCE->emitInt32(EndLabelPtr - BeginLabelPtr);
430     //Asm->EOL("Region length");
431
432     if (!S.PadLabel) {
433       JCE->emitInt32(0);
434     } else {
435       unsigned PadLabelPtr = JCE->getLabelAddress(S.PadLabel);
436       JCE->emitInt32(PadLabelPtr - (intptr_t)StartFunction);
437     }
438     // Asm->EOL("Landing pad");
439
440     JCE->emitULEB128Bytes(S.Action);
441     // Asm->EOL("Action");
442   }
443
444   // Emit the actions.
445   for (unsigned I = 0, N = Actions.size(); I != N; ++I) {
446     ActionEntry &Action = Actions[I];
447
448     JCE->emitSLEB128Bytes(Action.ValueForTypeID);
449     //Asm->EOL("TypeInfo index");
450     JCE->emitSLEB128Bytes(Action.NextAction);
451     //Asm->EOL("Next action");
452   }
453
454   // Emit the type ids.
455   for (unsigned M = TypeInfos.size(); M; --M) {
456     const GlobalVariable *GV = TypeInfos[M - 1];
457
458     if (GV) {
459       if (TD->getPointerSize(GV->getType()->getAddressSpace()) == sizeof(int32_t))
460         JCE->emitInt32((intptr_t)Jit.getOrEmitGlobalVariable(GV));
461       else
462         JCE->emitInt64((intptr_t)Jit.getOrEmitGlobalVariable(GV));
463     } else {
464       if (TD->getPointerSize(0) == sizeof(int32_t))
465         JCE->emitInt32(0);
466       else
467         JCE->emitInt64(0);
468     }
469     // Asm->EOL("TypeInfo");
470   }
471
472   // Emit the filter typeids.
473   for (unsigned j = 0, M = FilterIds.size(); j < M; ++j) {
474     unsigned TypeID = FilterIds[j];
475     JCE->emitULEB128Bytes(TypeID);
476     //Asm->EOL("Filter TypeInfo index");
477   }
478
479   JCE->emitAlignmentWithFill(4, 0);
480
481   return DwarfExceptionTable;
482 }
483
484 unsigned char*
485 JITDwarfEmitter::EmitCommonEHFrame(const Function* Personality) const {
486   unsigned PointerSize = TD->getPointerSize(0);
487   int stackGrowth = stackGrowthDirection == TargetFrameLowering::StackGrowsUp ?
488           PointerSize : -PointerSize;
489
490   unsigned char* StartCommonPtr = (unsigned char*)JCE->getCurrentPCValue();
491   // EH Common Frame header
492   JCE->allocateSpace(4, 0);
493   unsigned char* FrameCommonBeginPtr = (unsigned char*)JCE->getCurrentPCValue();
494   JCE->emitInt32((int)0);
495   JCE->emitByte(dwarf::DW_CIE_VERSION);
496   JCE->emitString(Personality ? "zPLR" : "zR");
497   JCE->emitULEB128Bytes(1);
498   JCE->emitSLEB128Bytes(stackGrowth);
499   JCE->emitByte(RI->getDwarfRegNum(RI->getRARegister(), true));
500
501   if (Personality) {
502     // Augmentation Size: 3 small ULEBs of one byte each, and the personality
503     // function which size is PointerSize.
504     JCE->emitULEB128Bytes(3 + PointerSize);
505
506     // We set the encoding of the personality as direct encoding because we use
507     // the function pointer. The encoding is not relative because the current
508     // PC value may be bigger than the personality function pointer.
509     if (PointerSize == 4) {
510       JCE->emitByte(dwarf::DW_EH_PE_sdata4);
511       JCE->emitInt32(((intptr_t)Jit.getPointerToGlobal(Personality)));
512     } else {
513       JCE->emitByte(dwarf::DW_EH_PE_sdata8);
514       JCE->emitInt64(((intptr_t)Jit.getPointerToGlobal(Personality)));
515     }
516
517     // LSDA encoding: This must match the encoding used in EmitEHFrame ()
518     if (PointerSize == 4)
519       JCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
520     else
521       JCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8);
522     JCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
523   } else {
524     JCE->emitULEB128Bytes(1);
525     JCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
526   }
527
528   EmitFrameMoves(0, MAI->getInitialFrameState());
529
530   JCE->emitAlignmentWithFill(PointerSize, dwarf::DW_CFA_nop);
531
532   JCE->emitInt32At((uintptr_t*)StartCommonPtr,
533                    (uintptr_t)((unsigned char*)JCE->getCurrentPCValue() -
534                                FrameCommonBeginPtr));
535
536   return StartCommonPtr;
537 }
538
539
540 unsigned char*
541 JITDwarfEmitter::EmitEHFrame(const Function* Personality,
542                              unsigned char* StartCommonPtr,
543                              unsigned char* StartFunction,
544                              unsigned char* EndFunction,
545                              unsigned char* ExceptionTable) const {
546   unsigned PointerSize = TD->getPointerSize(0);
547
548   // EH frame header.
549   unsigned char* StartEHPtr = (unsigned char*)JCE->getCurrentPCValue();
550   JCE->allocateSpace(4, 0);
551   unsigned char* FrameBeginPtr = (unsigned char*)JCE->getCurrentPCValue();
552   // FDE CIE Offset
553   JCE->emitInt32(FrameBeginPtr - StartCommonPtr);
554   JCE->emitInt32(StartFunction - (unsigned char*)JCE->getCurrentPCValue());
555   JCE->emitInt32(EndFunction - StartFunction);
556
557   // If there is a personality and landing pads then point to the language
558   // specific data area in the exception table.
559   if (Personality) {
560     JCE->emitULEB128Bytes(PointerSize == 4 ? 4 : 8);
561
562     if (PointerSize == 4) {
563       if (!MMI->getLandingPads().empty())
564         JCE->emitInt32(ExceptionTable-(unsigned char*)JCE->getCurrentPCValue());
565       else
566         JCE->emitInt32((int)0);
567     } else {
568       if (!MMI->getLandingPads().empty())
569         JCE->emitInt64(ExceptionTable-(unsigned char*)JCE->getCurrentPCValue());
570       else
571         JCE->emitInt64((int)0);
572     }
573   } else {
574     JCE->emitULEB128Bytes(0);
575   }
576
577   // Indicate locations of function specific  callee saved registers in
578   // frame.
579   EmitFrameMoves((intptr_t)StartFunction, MMI->getFrameMoves());
580
581   JCE->emitAlignmentWithFill(PointerSize, dwarf::DW_CFA_nop);
582
583   // Indicate the size of the table
584   JCE->emitInt32At((uintptr_t*)StartEHPtr,
585                    (uintptr_t)((unsigned char*)JCE->getCurrentPCValue() -
586                                StartEHPtr));
587
588   // Double zeroes for the unwind runtime
589   if (PointerSize == 8) {
590     JCE->emitInt64(0);
591     JCE->emitInt64(0);
592   } else {
593     JCE->emitInt32(0);
594     JCE->emitInt32(0);
595   }
596
597   return StartEHPtr;
598 }