/* Put out assembler info before any code is generated */ header() { comment(); outstr(Banner); nl(); comment(); outstr(Author); nl(); comment(); outstr(Version); nl(); comment(); nl(); if ( trace ) { ol("global ccregis"); /* declare these */ ol("global ccleavi"); /* tracing routine */ } if ( mainflg ) { /* do stuff needed for first */ ol("LD HL,(6)"); /* set up stack */ ol("LD SP,HL"); callrts("ccgo"); /* set default drive for CP/M */ zcall("main"); /* call code generated by small-c */ zcall("exit"); } else { /* not main program, output module name */ ot("module "); if ( Filename[1] == ':' ) outstr(&Filename[2]); else outstr(Filename) ; nl(); } }
/* * print all assembler info before any code is generated * */ header () { outstr("|\tSmall C MC6809\n|\tCoder (2.4,84/11/27)\n|"); FEvers(); nl (); ol (".globl\tsmul,sdiv,smod,asr,asl,neg,lneg,case"); ol (".globl\teq,ne,lt,le,gt,ge,ult,ule,ugt,uge,bool"); }
void ClassLoaderData::Dependencies::locked_add(objArrayHandle last_handle, objArrayHandle new_dependency, Thread* THREAD) { // Have to lock and put the new dependency on the end of the dependency // array so the card mark for CMS sees that this dependency is new. // Can probably do this lock free with some effort. ObjectLocker ol(Handle(THREAD, _list_head), THREAD); oop loader_or_mirror = new_dependency->obj_at(0); // Since the dependencies are only added, add to the end. objArrayOop end = last_handle(); objArrayOop last = NULL; while (end != NULL) { last = end; // check again if another thread added it to the end. if (end->obj_at(0) == loader_or_mirror) { // Don't need to add it return; } end = (objArrayOop)end->obj_at(1); } assert (last != NULL, "dependencies should be initialized"); // fill in the first element with the oop in new_dependency. if (last->obj_at(0) == NULL) { last->obj_at_put(0, new_dependency->obj_at(0)); } else { last->obj_at_put(1, new_dependency()); } }
ExecStatus overload(Space& home, Propagator& p, TaskArray<OptTask>& t) { TaskViewArray<typename TaskTraits<OptTask>::TaskViewFwd> f(t); sort<typename TaskTraits<OptTask>::TaskViewFwd,STO_LCT,true>(f); Region r(home); OmegaLambdaTree<typename TaskTraits<OptTask>::TaskViewFwd> ol(r,f,false); bool to_purge = false; for (int i=0; i<f.size(); i++) { if (f[i].optional()) { ol.linsert(i); } else if (f[i].mandatory()) { ol.oinsert(i); if (ol.ect() > f[i].lct()) return ES_FAILED; } while (!ol.lempty() && (ol.lect() > f[i].lct())) { int j = ol.responsible(); GECODE_ME_CHECK(f[j].excluded(home)); ol.lremove(j); to_purge = true; } } if (to_purge) GECODE_ES_CHECK((purge<OptTask,Int::PC_INT_BND>(home,p,t))); return ES_OK; }
bool Triangle::hasMaterial(int i, TerrainMaterial *mat) { edPoint::OwnersList::iterator ow_it; edPoint::OwnersList &ol(v[i]->getTerrainOwnersList()); for (ow_it=ol.begin(); ow_it!=ol.end(); ++ow_it) if ((*ow_it)->material.get()==mat) return true; return false; }
void Editor::copy() { if (!activeStack() || selection_->empty()) return; ObjectList ol(*selection_, model_); QClipboard *clipboard = kapp->clipboard(); clipboard->setMimeData(ol.mimeData(), QClipboard::Clipboard); }
void exchange(tree_set_t& other, const Synchronized& sync) { if (this == &other) { return; } // ESSENTIAL: deadlock in such case m_arena.exchange(other.m_arena, sync); m_skeleton.exchange(other.m_skeleton, sync); lock_scope_t<self_type, Synchronized> tl(this); lock_scope_t<self_type, Synchronized> ol(&other); unfact::exchange(m_compare, other.m_compare); }
void testMat() { int k=FreqSys(1,1)/FreqSys(1,2); //cout<<k<<endl; math::matrix<double> yu(4,4); for (int i=0;i<4;i++) { yu(0,i)=i+1; yu(i,0)=i+1; if (i==1) { yu(1,1)=5;yu(1,i+1)=9;yu(1,i+2)=10; yu(1+i,1)=9;yu(i+2,1)=10; } yu(2,2)=22;yu(2,3)=20; yu(3,2)=20; yu(3,3)=37; } //cout<<yu<<endl; math::matrix<double> yk(4,4); math::matrix<double> ol(4,1); math::matrix<double>* yyy=new math::matrix<double>[2]; for (int i=0;i<4;i++) { for (int j=0;j<1;j++) { ol(i,j)=(i+1.2)+j*0.2; } //math::matrix<double> ols(4,1); } yyy[0]=ol; math::matrix<double>I(2,2); //cout<<yu<<endl; //cout<<InsertZeroCol(yu,0,1); for (int i=0;i<2;i++) { I(i,i)=12.0; } //cout<<Kronecker(yu,I,2); }
static void dumpfinal (void) { int i; if (leaf_cnt) { outstr("leaf_loc: .ds "); outdec(leaf_size); nl(); for (i = 0; i < leaf_cnt; i++) { outstr("__"); outstr(leaf_functions[i]); outstr("_lend:\n"); } } if (data) { fclose(data); outstr("huc_data:\n"); outstr("___huc_data:\n"); outstr(data_buf); outstr("huc_data_end:\n"); outstr("___huc_data_end:\n"); } if (globals_h_in_process != 1) outstr("__heap_start:\n"); if (rodata) { fclose(rodata); ol(".data"); ol(".bank CONST_BANK"); outstr("huc_rodata:\n"); outstr("___huc_rodata:\n"); outstr(rodata_buf); outstr("huc_rodata_end:\n"); outstr("___huc_rodata_end:\n"); } fseek(output, output_globdef, SEEK_SET); if (have_irq_handler || have_sirq_handler) outstr("HAVE_IRQ = 1\n"); if (have_sirq_handler) outstr("HAVE_SIRQ = 1\n"); if (have_init_data) outstr("HAVE_INIT = 1\n"); }
void DynNewtonianMCCMap::replicaExchange(Dynamics& oDynamics) { #ifdef DYNAMO_DEBUG if (dynamic_cast<const DynNewtonianMCCMap*>(&oDynamics) == NULL) M_throw() << "Trying to swap Dynamicss with different derived types!"; #endif DynNewtonianMCCMap& ol(static_cast<DynNewtonianMCCMap&>(oDynamics)); std::swap(_W, ol._W); }
void DynNewtonianMC::swapSystem(Dynamics& oDynamics) { #ifdef DYNAMO_DEBUG if (dynamic_cast<const DynNewtonianMC*>(&oDynamics) == NULL) M_throw() << "Trying to swap Dynamicss with different derived types!"; #endif DynNewtonianMC& ol(static_cast<DynNewtonianMC&>(oDynamics)); std::swap(EnergyPotentialStep, ol.EnergyPotentialStep); std::swap(_W, ol._W); }
TerrainMaterial *Triangle::getValidMaterial(int i) { TerrainMaterial *ret= NULL; edPoint::OwnersList::iterator ow_it; edPoint::OwnersList &ol(v[i]->getTerrainOwnersList()); printf("owners %d\n",ol.size()); for (ow_it=ol.begin(); ow_it!=ol.end(); ++ow_it) { if ((*ow_it)->material.valid()) ret= (*ow_it)->material.get(); } // return (*ow_it)->material.get(); return ret; // return NULL; }
void readline (void) { int k; FILE *unit; FOREVER { if (feof (input)) return; if ((unit = input2) == NULL) unit = input; kill_line (); while ((k = fgetc (unit)) != EOF) { if ((k == '\r') | (k == EOL) | (lptr >= LINEMAX)) break; line[lptr++] = k; } line_number++; line[lptr] = 0; if (k <= 0) if (input2 != NULL) { if (globals_h_in_process) { /* Add special treatment to ensure globals.h stuff appears at the beginning */ dumpglbs(); ol(".code"); globals_h_in_process = 0; } input2 = inclstk[--inclsp]; line_number = inclstk_line[inclsp]; fclose (unit); } if (lptr) { if ((ctext) & (cmode)) { flush_ins(); comment (); outstr (line); newl (); } lptr = 0; return; } } }
void thread_main() { winapi::file_notify_information_buffer buf( 2048 ); for( ;; ) { winapi::overlapped_t ol( event_ ); event_.reset(); if( exit_flag_ ) { break; } if( !winapi::read_directory_change( dir_, buf, true, FILE_NOTIFY_CHANGE_LAST_WRITE, ol ) ) { break; } if( !winapi::get_overlapped_result( dir_, ol, true ) ) { break; } winapi::enum_file_notify_information( buf, f_ ); } }
void dopsdinc(void) { INTPTR_T dummy; /* Used in the qstr function, I don't know its utility yet */ int numericarg = 0; /* Number of numeric arg to test validity */ if (amatch("pal",3)) { if (!match("(")) error("missing ("); ol(".data"); ol(".dw $0"); readstr(); /* read the label name */ prefix(); outstr(litq2); outstr(":\n"); addglb_far(litq2, CINT); if (!match(",")) { error("missing ,"); kill_line(); return; } ot(".incpal \""); if (readqstr() == 0) /* read the filename */ { error("bad filename in incpal"); kill_line(); return; } outstr(litq2); outstr("\""); if (match(",")) outstr(","); numericarg = 0; while (!match(")")) { numericarg++; number(&dummy); outdec(dummy); if (match(",")) outstr(","); } newl(); ol(".code"); if (numericarg>2) error("Maximum 2 numeric arg for incpal(name,\"filename\" [,start_pal] [,nb_pal])"); kill_line(); } else if (amatch("bin",3)) { if (!match("(")) error("missing ("); ol(".data"); ol(".dw $0"); readstr(); /* read the label name */ prefix(); outstr(litq2); outstr(":\n"); addglb_far(litq2, CCHAR); if (!match(",")) { error("missing ,"); kill_line(); return; } ot(".incbin \""); if (readqstr() == 0) /* read the filename */ { error("bad filename in incbin"); kill_line(); return; } outstr(litq2); outstr("\"\n"); if (!match(")")) error("missing )"); newl(); ol(".code"); kill_line(); } else if (amatch("bat",3)) { if (!match("(")) error("missing ("); ol(".data"); ol(".dw $0"); readstr(); /* read the label name */ prefix(); outstr(litq2); outstr(":\n"); addglb_far(litq2, CINT); if (!match(",")) { error("missing ,"); kill_line(); return; } ot(".incbat \""); if (readqstr() == 0) { error("bad filename in incbat"); kill_line(); return; } outstr(litq2); outstr("\""); if (match(",")) outstr(","); numericarg = 0; while (!match(")")) { numericarg++; number(&dummy); outdec(dummy); if (match(",")) outstr(","); } newl(); ol(".code"); if ((numericarg!=1) && (numericarg!=3) && (numericarg!=5)) error("Either 1,3 or 5 numeric arguments are needed for incbat statement"); kill_line(); } else if (amatch("spr",3)) { if (!match("(")) error("missing ("); ol(".data"); ol(".dw $0"); readstr(); /* read the label name */ prefix(); outstr(litq2); outstr(":\n"); addglb_far(litq2, CINT); if (!match(",")) { error("missing ,"); kill_line(); return; } ot(".incspr \""); if (readqstr() == 0) { error("bad filename in incspr"); kill_line(); return; } outstr(litq2); outstr("\""); if (match(",")) outstr(","); numericarg = 0; while (!match(")")) { numericarg++; number(&dummy); outdec(dummy); if (match(",")) outstr(","); } newl(); ol(".code"); if ((numericarg!=0) && (numericarg!=2) && (numericarg!=4)) error("Either 0,2 or 4 numeric arguments are needed for incspr statement"); kill_line(); } else if (amatch("chr",3)) { if (!match("(")) error("missing ("); ol(".data"); ol(".dw $0800"); readstr(); /* read the label name */ prefix(); outstr(litq2); outstr(":\n"); addglb_far(litq2, CINT); if (!match(",")) { error("missing ,"); kill_line(); return; } ot(".incchr \""); if (readqstr() == 0) { error("bad filename in incchr"); kill_line(); return; } outstr(litq2); outstr("\""); if (match(",")) outstr(","); numericarg = 0; while (!match(")")) { numericarg++; number(&dummy); outdec(dummy); if (match(",")) outstr(","); } newl(); ol(".code"); if ((numericarg!=0) && (numericarg!=2) && (numericarg!=4)) error("Either 0,2 or 4 numeric arguments are needed for incchr statement"); kill_line(); } else if (amatch("chr_ex",6)) { do_inc_ex(8); } else if (amatch("tile",4)) { if (!match("(")) error("missing ("); ol(".data"); ol(".dw $1000"); readstr(); /* read the label name */ prefix(); outstr(litq2); outstr(":\n"); addglb_far(litq2, CINT); if (!match(",")) { error("missing ,"); kill_line(); return; } ot(".inctile \""); if (readqstr() == 0) { error("bad filename in inctile"); kill_line(); return; } outstr(litq2); outstr("\""); if (match(",")) outstr(","); numericarg = 0; while (!match(")")) { numericarg++; number(&dummy); outdec(dummy); if (match(",")) outstr(","); } newl(); ol(".code"); if ((numericarg!=0) && (numericarg!=2) && (numericarg!=4)) error("Either 0,2 or 4 numeric arguments are needed for inctile statement"); kill_line(); } else if (amatch("tile_ex",7)) { do_inc_ex(16); } else { error("Unknown include directive"); kill_line(); } return; }
CMUK_ERROR_CODE cmuk::computeFootIK( LegIndex leg, const vec3f& pos, vec3f* q_bent_forward, vec3f* q_bent_rearward ) const { if ((int)leg < 0 || (int)leg >= NUM_LEGS) { return CMUK_BAD_LEG_INDEX; } else if (!q_bent_forward || !q_bent_rearward) { return CMUK_INSUFFICIENT_ARGUMENTS; } debug << "*** computing IK...\n"; int hipflags = 0; // subtract off hip position vec3f p = pos - jo(_kc, leg, HIP_RX_OFFSET, _centeredFootIK); vec3f orig = pos; // get dist from hip rx joint to y rotation plane const float& d = jo(_kc, leg, HIP_RY_OFFSET, _centeredFootIK)[1]; // get the squared length of the distance on the plane float yz = p[1]*p[1] + p[2]*p[2]; // alpha is the angle of the foot in the YZ plane with respect to the Y axis float alpha = atan2(p[2], p[1]); // h is the distance of foot from hip in YZ plane float h = sqrt(yz); // beta is the angle between the foot-hip vector (projected in YZ // plane) and the top hip link. float cosbeta = d / h; debug << "p = " << p << ", d = " << d << ", yz = " << yz << "\nalpha = " << alpha << ", h = " << h << ", cosbeta=" << cosbeta << "\n"; if (fabs(cosbeta) > 1) { debug << "violated triangle inequality when calculating hip_rx_angle!\n" ; if (fabs(cosbeta) - 1 > 1e-4) { hipflags = hipflags | IK_UPPER_DISTANCE; } cosbeta = (cosbeta < 0) ? -1 : 1; if (yz < 1e-4) { p[1] = d; p[2] = 0; } else { float scl = fabs(d) / h; p[1] *= scl; p[2] *= scl; orig = p + jo(_kc, leg, HIP_RX_OFFSET, _centeredFootIK); } } float beta = acos(cosbeta); // Now compute the two possible hip angles float hip_rx_angles[2], badness[2]; int flags[2]; flags[0] = hipflags; flags[1] = hipflags; hip_rx_angles[0] = fix_angle(alpha - beta, -M_PI, M_PI); hip_rx_angles[1] = fix_angle(alpha + beta, -M_PI, M_PI); const float& min = jl(_kc, leg, HIP_RX, 0); const float& max = jl(_kc, leg, HIP_RX, 1); // See how badly we violate the joint limits for this hip angles for (int i=0; i<2; ++i) { float& angle = hip_rx_angles[i]; badness[i] = fabs(compute_badness(angle, min, max)); if (badness[i]) { flags[i] = flags[i] | IK_UPPER_ANGLE_RANGE; } } // Put the least bad (and smallest) hip angle first bool swap = false; if ( badness[1] <= badness[0] ) { // We want the less bad solution for hip angle swap = true; } else if (badness[0] == 0 && badness[1] == 0) { // We want the solution for hip angle that leaves the hip up. if ((leg == FL || leg == HL) && hip_rx_angles[0] > hip_rx_angles[1]) { swap = true; } else if ((leg == FR || leg == HR) && hip_rx_angles[0] < hip_rx_angles[1]) { swap = true; } } if (swap) { std::swap(hip_rx_angles[0], hip_rx_angles[1]); std::swap(badness[0], badness[1]); std::swap(flags[0], flags[1]); } int hip_solution_cnt = 2; if (badness[0] == 0 && badness[1] != 0) { hip_solution_cnt = 1; } debug << "hip_rx_angles[0]=" << hip_rx_angles[0] << ", badness=" << badness[0] << ", flags=" << flags[0] << "\n"; debug << "hip_rx_angles[1]=" << hip_rx_angles[1] << ", badness=" << badness[1] << ", flags=" << flags[1] << "\n"; debug << "hip_solution_cnt = " << hip_solution_cnt << "\n"; vec3f qfwd[2], qrear[2]; for (int i=0; i<hip_solution_cnt; ++i) { debug << "** computing ll solution " << (i+1) << " of " << (hip_solution_cnt) << "\n"; float hip_rx = hip_rx_angles[i]; // now make inv. transform to get rid of hip rotation Transform3f tx = Transform3f::rx(hip_rx, jo(_kc, leg, HIP_RX_OFFSET, _centeredFootIK)); vec3f ptx = tx.transformInv(orig); debug << "tx=[" << tx.translation() << ", " << tx.rotation() << "], ptx = " << ptx << "\n"; // calculate lengths for cosine law float l1sqr = ol2(_kc, leg, KNEE_RY_OFFSET, _centeredFootIK); float l2sqr = ol2(_kc, leg, FOOT_OFFSET, _centeredFootIK); float l1 = ol(_kc, leg, KNEE_RY_OFFSET, _centeredFootIK); float l2 = ol(_kc, leg, FOOT_OFFSET, _centeredFootIK); float ksqr = ptx[0]*ptx[0] + ptx[2]*ptx[2]; float k = sqrt(ksqr); debug << "l1=" << l1 << ", l2=" << l2 << ", k=" << k << "\n"; // check triangle inequality if (k > l1 + l2) { debug << "oops, violated the triangle inequality for lower segments: " << "k = " << k << ", " << "l1 + l2 = " << l1 + l2 << "\n"; if (k - (l1 + l2) > 1e-4) { flags[i] = flags[i] | IK_LOWER_DISTANCE; } k = l1 + l2; ksqr = k * k; } // 2*theta is the acute angle formed by the spread // of the two hip rotations... float costheta = (l1sqr + ksqr - l2sqr) / (2 * l1 * k); if (fabs(costheta) > 1) { debug << "costheta = " << costheta << " > 1\n"; if (fabs(costheta) - 1 > 1e-4) { flags[i] = flags[i] | IK_LOWER_DISTANCE; } costheta = (costheta < 0) ? -1 : 1; } float theta = acos(costheta); // gamma is the angle of the foot with respect to the z axis float gamma = atan2(-ptx[0], -ptx[2]); // hip angles are just offsets off of gamma now float hip_ry_1 = gamma - theta; float hip_ry_2 = gamma + theta; // phi is the obtuse angle of the parallelogram float cosphi = (l1sqr + l2sqr - ksqr) / (2 * l1 * l2); if (fabs(cosphi) > 1) { debug << "cosphi = " << cosphi << " > 1\n"; if (fabs(cosphi) - 1 > 1e-4) { flags[i] = flags[i] | IK_LOWER_DISTANCE; } cosphi = (cosphi < 0) ? -1 : 1; } float phi = acos(cosphi); // epsilon is the "error" caused by not having feet offset directly // along the z-axis (if they were, epsilon would equal zero) float epsilon = le(_kc, leg, _centeredFootIK); // now we can directly solve for knee angles float knee_ry_1 = M_PI - phi - epsilon; float knee_ry_2 = -M_PI + phi - epsilon; // now fill out angle structs and check limits qfwd[i] = vec3f(hip_rx, hip_ry_1, knee_ry_1); qrear[i] = vec3f(hip_rx, hip_ry_2, knee_ry_2); debug << "before wrap, qfwd = " << qfwd[i] << "\n"; debug << "before wrap, qrear = " << qrear[i] << "\n"; check_wrap(_kc, qfwd[i], leg); check_wrap(_kc, qrear[i], leg); debug << "after wrap, qfwd = " << qfwd[i] << "\n"; debug << "after wrap, qrear = " << qrear[i] << "\n"; if (!check_limits(_kc, qfwd[i], leg)) { debug << "violated limits forward!\n"; flags[i] = flags[i] | IK_LOWER_ANGLE_RANGE_FWD; } if (!check_limits(_kc, qrear[i], leg)) { debug << "violated limits rearward!\n"; flags[i] = flags[i] | IK_LOWER_ANGLE_RANGE_REAR; } } // for each viable hip solution int best = 0; if (hip_solution_cnt == 2) { if (howbad(flags[0]) > howbad(flags[1])) { best = 1; } debug << "best overall solution is " << (best+1) << "\n"; } *q_bent_forward = qfwd[best]; *q_bent_rearward = qrear[best]; return flags_to_errcode(flags[best]); }
void do_inc_ex(int type) { int end; int i; INTPTR_T j; int num; int nb_tile; char label[NAMESIZE]; char label2[NAMESIZE]; char str[NAMESIZE+32]; struct { char fname[FILENAMESIZE]; INTPTR_T arg[5]; } tiles[16]; if(!match("(")) { error("missing '('"); kill_line(); return; } readstr(); /* read the label name */ strcpy(label, litq2); strcpy(label2, litq2); strcpy(str, "__data__"); for(i = (int)strlen(label2), j = 0; i < NAMEMAX; i++) label2[i] = str[j++]; label2[i] = '\0'; addglb(label2, ARRAY, CINT, 0, EXTERN); addglb(label, ARRAY, CINT, 0, EXTERN); if(!match(",")) { error("comma missing"); kill_line(); return; } end = 0; num = 0; nb_tile = 0; while (!end) { // if (match("\\")); if(!readqstr()) { error("not a file name"); kill_line(); return; } if(!match(",")) { error("comma missing"); kill_line(); return; } strcpy(tiles[num].fname, litq2); for (i = 0; i < 5; i++) { // if (match("\\")); if(!number(&tiles[num].arg[i])) { error("not a number"); kill_line(); return; } if (match(")")) { if (i == 4) { kill_line(); end = 1; break; } else { error("arg missing"); kill_line(); return; } } if(!match(",")) { error("comma missing"); kill_line(); return; } while((ch() == ' ') || (ch() == '\t')) gch(); if (ch() == '\0') { error("arg missing"); kill_line(); return; } } nb_tile += tiles[num].arg[2] * tiles[num].arg[3]; num++; if (num == 16) { if(!end) { error("too many args (max 16 files)"); kill_line(); return; } } } /* create const array to hold extra infos */ new_const(); const_val[const_val_idx++] = const_data_idx; /* number of tile */ sprintf(str, "%i", nb_tile); add_buffer(str, '('); const_data[const_data_idx++] = '\0'; const_val[const_val_idx++] = const_data_idx; /* tile size */ sprintf(str, "%i", type); add_buffer(str, '('); const_data[const_data_idx++] = '\0'; const_val[const_val_idx++] = const_data_idx; /* tile bank */ sprintf(str, "BANK(_%s)", label2); add_buffer(str, '('); const_data[const_data_idx++] = '\0'; const_val[const_val_idx++] = const_data_idx; /* tile addr */ sprintf(str, " _%s", label2); add_buffer(str, '('); const_data[const_data_idx++] = '\0'; const_val[const_val_idx++] = -(litptr + 1024); /* pal idx table addr */ add_const(CINT); /* create pal idx table */ for(i = 0; i < num; i++) { j = tiles[i].arg[2] * tiles[i].arg[3]; while (j) { j--; if (litptr < LITMAX) litq[litptr++] = (tiles[i].arg[4] << 4); } } /* dump incchr/tile cmds */ ol(".data"); if (type == 8) ol(".dw $0800"); else ol(".dw $1000"); prefix(); outstr(label2); outstr(":\n"); for(i = 0; i < num; i++) { if (type == 8) ot(".incchr \""); else ot(".inctile \""); outstr(tiles[i].fname); outstr("\""); for (j = 0; j < 4; j++) { outstr(","); outdec(tiles[i].arg[j]); } newl(); } ol(".code"); kill_line(); }
bool downloadOSM(MainWindow* Main, const CoordBox& aBox , Document* theDocument) { QString osmWebsite, osmUser, osmPwd; static bool DownloadRaw = false; QDialog * dlg = new QDialog(Main); osmWebsite = M_PREFS->getOsmApiUrl(); osmUser = M_PREFS->getOsmUser(); osmPwd = M_PREFS->getOsmPassword(); Ui::DownloadMapDialog ui; ui.setupUi(dlg); SlippyMapWidget* SlippyMap = new SlippyMapWidget(ui.groupBox); #ifndef _MOBILE SlippyMap->setMinimumHeight(256); #endif CoordBox Clip(aBox); SlippyMap->setViewportArea(Clip); ui.verticalLayout->addWidget(SlippyMap); QObject::connect(SlippyMap, SIGNAL(redraw()), ui.FromMap, SLOT(toggle())); BookmarkListIterator i(*(M_PREFS->getBookmarks())); while (i.hasNext()) { i.next(); if (i.value().deleted == false) ui.Bookmarks->addItem(i.key()); } ui.edXapiUrl->setText(QString("*[bbox=%1,%2,%3,%4]").arg(aBox.bottomLeft().x(), 0, 'f').arg(aBox.bottomLeft().y(), 0, 'f').arg(aBox.topRight().x(), 0, 'f').arg(aBox.topRight().y(), 0, 'f')); ui.IncludeTracks->setChecked(DownloadRaw); ui.ResolveRelations->setChecked(M_PREFS->getResolveRelations()); bool OK = true, retry = true, directAPI = false; QString directUrl; while (retry) { retry = false; #ifdef _MOBILE dlg->setWindowState(Qt::WindowMaximized); #endif if (dlg->exec() == QDialog::Accepted) { DownloadRaw = false; if (ui.FromBookmark->isChecked()) { Clip = M_PREFS->getBookmarks()->value(ui.Bookmarks->currentText()).Coordinates; } else if (ui.FromView->isChecked()) { Clip = aBox; } else if (ui.FromLink->isChecked()) { QString link = ui.Link->text(); if (link.contains("/api/")) { directAPI=true; directUrl = link; } else if (link.contains("/browse/")) { QString tag("/browse/"); int ix = link.lastIndexOf(tag) + tag.length(); directUrl = M_PREFS->getOsmApiUrl(); if (!directUrl.endsWith("/")) directUrl += "/"; directUrl += link.right(link.length() - ix); if (!directUrl.endsWith("/")) directUrl += "/"; directUrl += "full"; directAPI=true; } else if (link.startsWith("way") || link.startsWith("node") || link.startsWith("relation")) { directUrl = M_PREFS->getOsmApiUrl(); if (!directUrl.endsWith("/")) directUrl += "/"; directUrl += link; directAPI=true; } else { OsmLink ol(link); Clip = ol.getCoordBox(); if (Clip.isNull() || Clip.isEmpty()) retry = true; } } else if (ui.FromXapi->isChecked()) { directAPI = true; directUrl = M_PREFS->getXapiUrl(); if (!directUrl.endsWith("/")) directUrl += "/"; directUrl += ui.edXapiUrl->text(); } else if (ui.FromMap->isChecked()) { QRectF R(SlippyMap->viewArea()); Clip = CoordBox(Coord(R.x(), R.y()), Coord(R.x()+R.width(), R.y()+R.height())); } if (retry) continue; Main->view()->setUpdatesEnabled(false); Layer* theLayer = new DrawingLayer(QApplication::translate("Downloader","%1 download").arg(QDateTime::currentDateTime().toString(Qt::ISODate))); theDocument->add(theLayer); M_PREFS->setResolveRelations(ui.ResolveRelations->isChecked()); if (directAPI) { if (ui.FromXapi->isChecked()) theLayer->setUploadable(false); OK = downloadOSM(Main,QUrl(QUrl::fromEncoded(directUrl.toLatin1())),osmUser,osmPwd,theDocument,theLayer); } else OK = downloadOSM(Main,osmWebsite,osmUser,osmPwd,Clip,theDocument,theLayer); if (OK && ui.IncludeTracks->isChecked()) OK = downloadTracksFromOSM(Main,osmWebsite,osmUser,osmPwd, Clip,theDocument); Main->view()->setUpdatesEnabled(true); if (OK) { theDocument->setLastDownloadLayer(theLayer); theDocument->addDownloadBox(theLayer, Clip); #ifndef _MOBILE if (directAPI) Main->on_viewZoomAllAction_triggered(); else #endif Main->view()->setViewport(Clip,Main->view()->rect()); Main->invalidateView(); } else { retry = true; theDocument->remove(theLayer); SAFE_DELETE(theLayer); } } } delete dlg; return OK; }
// ExpBitMuxFunction::pCodeGenerate // // Generate PCI's for the BitMux operation. For now, only handle certain // cases which give signifigant speedup. Otherwise, use CLAUSE_EVAL. // // IN : space - memory allocator // RETURN : ex_expr::EXPR_OK is no errors // EFFECTS: stores pointer to PCodeObject in clause // ex_expr::exp_return_type ExpBitMuxFunction::pCodeGenerate(Space *space, UInt32 f) { // What is the arity? // Int32 numOperands = getNumOperands(); // Get a handle on the operands. // AttributesPtr *attrs = getOperand(); // Only support operations to/from ATPs with INT's or CHAR datatype. // // Dst must be ATP // if(attrs[0]->getAtpIndex() < 2) return ex_clause::pCodeGenerate(space, f); Int32 i=1; for(; i<numOperands; i++) { // Src must be ATP // if(attrs[i]->getAtpIndex() < 2) return ex_clause::pCodeGenerate(space, f); // No varchars // if(attrs[i]->getVCIndicatorLength() > 0) return ex_clause::pCodeGenerate(space, f); // No nulls. Fix for genesis case 10-980114-7618 : AS 01/22/98 // if(attrs[i]->getNullIndicatorLength() > 0) return ex_clause::pCodeGenerate(space, f); // Only ints or chars. // switch(attrs[i]->getDatatype()) { case REC_BPINT_UNSIGNED: case REC_BIN16_SIGNED: case REC_BIN16_UNSIGNED: case REC_BIN32_SIGNED: case REC_BIN32_UNSIGNED: case REC_BIN64_SIGNED: case REC_BYTE_F_ASCII: break; default: return ex_clause::pCodeGenerate(space, f); break; } } // Allocate the code list. // PCIList code(space); // Generate pre clause PCI's. // PCode::preClausePCI(this, code); // Load and store each input value. // Int32 offset = attrs[0]->getOffset(); AML aml(PCIT::MBIN8, PCIT::MBIN8, PCIT::IBIN32S); for(i=1; i<numOperands; i++) { if(attrs[i]->getNullFlag()) { OL ol(attrs[0]->getAtp(), attrs[0]->getAtpIndex(), offset, attrs[i]->getAtp(), attrs[i]->getAtpIndex(), attrs[i]->getNullIndOffset(), 2); PCI pci(PCIT::Op_MOVE, aml, ol); code.append(pci); offset += 2; } OL ol(attrs[0]->getAtp(), attrs[0]->getAtpIndex(), offset, attrs[i]->getAtp(), attrs[i]->getAtpIndex(), attrs[i]->getOffset(), attrs[i]->getLength()); PCI pci(PCIT::Op_MOVE, aml, ol); code.append(pci); offset += attrs[i]->getLength(); } // Generate post clause PCI's // PCode::postClausePCI(this, code); setPCIList(code.getList()); return ex_expr::EXPR_OK; };
forceinline ExecStatus edgefinding(Space& home, int c, TaskViewArray<TaskView>& t) { sort<TaskView,STO_LCT,false>(t); Region r(home); /////////////////////// // Detection int* prec = r.alloc<int>(t.size()); for (int i=t.size(); i--; ) prec[i] = t[i].ect(); OmegaLambdaTree<TaskView> ol(r,c,t); for (int j=0; j<t.size(); j++) { while (!ol.lempty() && (ol.lenv() > static_cast<long long int>(c)*t[j].lct())) { int i = ol.responsible(); prec[i] = std::max(prec[i], t[j].lct()); ol.lremove(i); } ol.shift(j); } /////////////////////// // Propagation // Compute array of unique capacities and a mapping // from the task array to the corresponding entry in // the capacity array int* cap = r.alloc<int>(t.size()); for (int i=t.size(); i--;) cap[i] = i; SortMap<TaskView,StoCap,true> o(t); Support::quicksort(cap, t.size(), o); int* capacities = r.alloc<int>(t.size()); int* capInv = r.alloc<int>(t.size()); for (int i=t.size(); i--;) { capacities[cap[i]] = t[i].c(); capInv[cap[i]] = i; } int n_c = 0; for (int i=0, cur_c=INT_MIN; i<t.size(); i++) { if (capacities[i] != cur_c) capacities[n_c++] = cur_c = capacities[i]; cap[capInv[i]] = n_c-1; } r.free<int>(capInv, t.size()); // Compute update values for each capacity and LCut int* update = r.alloc<int>(t.size()*n_c); for (int i=t.size()*n_c; i--;) update[i] = -Int::Limits::infinity; ExtOmegaTree<TaskView> eo(r,c,ol); for (int i=0; i<n_c; i++) { eo.init(capacities[i]); int u = -Int::Limits::infinity; for (int j=t.size(); j--;) { long long int lctj = static_cast<long long int>(c-capacities[i])*t[j].lct(); long long int eml = plus(eo.env(j), -lctj); long long int diff_l; if (eml == -Limits::llinfinity) diff_l = -Limits::llinfinity; else diff_l = ceil_div_xx(eml, static_cast<long long int>(capacities[i])); int diff = (diff_l <= -Limits::infinity) ? -Limits::infinity : static_cast<int>(diff_l); u = std::max(u,diff); update[i*t.size()+j] = u; } } // Update est by iterating in parallel over the prec array // and the task array, both sorted by lct int* precMap = r.alloc<int>(t.size()); for (int i=t.size(); i--;) precMap[i] = i; PrecOrder po(prec); Support::quicksort(precMap, t.size(), po); int curJ = 0; for (int i=0; i<t.size(); i++) { // discard any curJ with lct > prec[i]: while (curJ < t.size() && t[curJ].lct() > prec[precMap[i]]) curJ++; if (curJ >= t.size()) break; // if lct[curJ] == prec[i], then LCut(T,j) <= i, so update est[i] int locJ = curJ; do { if (t[locJ].lct() != t[precMap[i]].lct()) { GECODE_ME_CHECK(t[precMap[i]].est(home,update[cap[precMap[i]]*t.size()+locJ])); break; } } while (t[locJ].lct() == prec[precMap[i]] && locJ++ < t.size() - 1); } return ES_OK; }
int main(int argc) { seal::PluginManager::get()->initialise(); pool::URIParser p; p.parse(); pool::IFileCatalog lcat; pool::IFileCatalog * cat = &lcat; cat->setWriteCatalog(p.contactstring()); cat->connect(); cat->start(); pool::IDataSvc *svc = pool::DataSvcFactory::instance(cat); // Define the policy for the implicit file handling pool::DatabaseConnectionPolicy policy; policy.setWriteModeForNonExisting(pool::DatabaseConnectionPolicy::CREATE); // policy.setWriteModeForExisting(pool::DatabaseConnectionPolicy::OVERWRITE); policy.setWriteModeForExisting(pool::DatabaseConnectionPolicy::UPDATE); svc->session().setDefaultConnectionPolicy(policy); svc->transaction().start(pool::ITransaction::UPDATE); pool::Ref<NavigationTests::AS> as(svc, new NavigationTests::AS); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. as.markWrite(place); } as->p.t=new NavigationTests::BT; as->p.t->k = 3; // svc->transaction().start(pool::ITransaction::UPDATE); pool::Ref<NavigationTests::T2> o1(svc, new NavigationTests::T2); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o1.markWrite(place); } pool::Ref<NavigationTests::T2> o2(svc, new NavigationTests::T2); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o2.markWrite(place); } pool::Ref<NavigationTests::T2> o3(svc, new NavigationTests::T2); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o3.markWrite(place); } pool::Ref<NavigationTests::T2> o5(svc, new NavigationTests::T2); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o5.markWrite(place); } pool::Ref<NavigationTests::K> o4(svc, new NavigationTests::K); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "K", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. o4.markWrite(place); } o3->bs.push_back(o1); o3->bs.push_back(o2); o3->bs.push_back(o5); o5->bs.push_back(o2); std::cout << "vec size " << o3->bs.size() << std::endl; // svc->cacheSvc().resetCache(); o1.reset(); std::cout << "o1 " << o1.toString() << std::endl; std::cout << "o1 o " << o1.isOpen() <<std:: endl; std::cout << "o1 p " << o1.isNull() << std::endl; std::cout << "o2 p " << o2.isNull() << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); svc->cacheSvc().resetCache(); svc->transaction().start(pool::ITransaction::UPDATE); // std::cout << "o1 p " << o1.isNull() << std::endl; std::cout << "o1 " << o1.toString() << std::endl; std::cout << "o1 o " << o1.isOpen() <<std:: endl; std::cout << "o1 p " << o1.isNull() << std::endl; o1.markDelete(); o1.reset(); std::cout << "after delete and reset" << std::endl; std::cout << "o1 " << o1.toString() << std::endl; std::cout << "o1 o " << o1.isOpen() <<std:: endl; std::cout << "o1 p " << o1.isNull() << std::endl; std::cout << "o2 d " << o2.toString() << std::endl; std::cout << "o2 t " << o2.token() << std::endl; std::cout << "o2 p " << o2.isNull() << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); svc->transaction().start(pool::ITransaction::UPDATE); std::cout << "vec size " << o3->bs.size() << std::endl; std::cout << "here we do not die anymore..." << std::endl; std::cout << "o2 d " << o2.toString() << std::endl; std::cout << "o2 t " << o2.token() << std::endl; std::cout << "o2 p " << o2.isNull() << std::endl; pool::Ref<NavigationTests::T2> o22 = o2; svc->transaction().commit(); svc->session().disconnectAll(); svc->cacheSvc().resetCache(); svc->transaction().start(pool::ITransaction::UPDATE); std::cout << "vec size " << o3->bs.size() << std::endl; o3->bs.push_back(o5); o3.markUpdate(); std::cout << "vec size " << o3->bs.size() << std::endl; svc->transaction().commit(); if (argc>1) svc->session().disconnectAll(); svc->cacheSvc().resetCache(); svc->transaction().start(pool::ITransaction::UPDATE); std::cout << "vec size " << o3->bs.size() << std::endl; o3->bs.push_back(o5); std::cout << "vec size " << o3->bs.size() << std::endl; o3.markUpdate(); svc->transaction().commit(); svc->session().disconnectAll(); svc->cacheSvc().resetCache(); svc->transaction().start(pool::ITransaction::UPDATE); std::cout << "o1 d " << o1.toString() << std::endl; std::cout << "o1 t " << o1.token() << std::endl; std::cout << "o1 p " << o1.isNull() << std::endl; std::cout << "o2 d " << o2.toString() << std::endl; std::cout << "o2 t " << o2.token() << std::endl; std::cout << "o2 p " << o2.isNull() << std::endl; /// this is true??? svc->transaction().commit(); svc->session().disconnectAll(); try { svc->transaction().start(pool::ITransaction::UPDATE); std::cout << "o2 d " << o2.toString() << std::endl; std::cout << "o2 t " << o2.token() << std::endl; std::cout << "o2 p " << o2.isNull() << std::endl; o2.markUpdate(); std::cout << "after update 1" << std::endl; o2.markDelete(); std::cout << "after delete 1" << std::endl; o2.markUpdate(); std::cout << "after update 2" << std::endl; o2.markDelete(); std::cout << "after delete 2" << std::endl; o22.markDelete(); std::cout << "after delete 22" << std::endl; o3.markDelete(); std::cout << "after delete 3" << std::endl; pool::Ref<NavigationTests::T2> ol(svc, new NavigationTests::T2); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. ol.markWrite(place); } svc->transaction().commit(); svc->session().disconnectAll(); } catch(const seal::Error& er){ std::cout << "caught seal exception " << std::endl; std::cerr << er.explainSelf(); std::cerr << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); } svc->transaction().start(pool::ITransaction::UPDATE); pool::Ref<NavigationTests::T2> oA(svc,new NavigationTests::T2); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. oA.markWrite(place); } svc->transaction().commit(); svc->session().disconnectAll(); svc->transaction().start(pool::ITransaction::UPDATE); oA.markDelete(); pool::Ref<NavigationTests::T2> oB(svc,new NavigationTests::T2); { pool::Placement place("DN", pool::DatabaseSpecification::PFN, "L", ROOT::Reflex::Type(), pool::ROOTKEY_StorageType.type()); // This will also register the file. For this to occur, the placement object must use a PFN. oB.markWrite(place); } oA = oB; svc->transaction().commit(); svc->session().disconnectAll(); try { svc->transaction().start(pool::ITransaction::UPDATE); oA.markDelete(); std::cout << "after delete A" << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); } catch(const seal::Error& er){ std::cout << "caught seal exception " << std::endl; std::cerr << er.explainSelf(); std::cerr << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); } try { svc->transaction().start(pool::ITransaction::UPDATE); o5.markDelete(); std::cout << "after delete 5" << std::endl; o3.markDelete(); std::cout << "after delete 3 2" << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); } catch(const seal::Error& er){ std::cout << "OK! caught seal exception " << std::endl; std::cerr << er.explainSelf(); std::cerr << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); } try { svc->transaction().start(pool::ITransaction::READ); pool::Ref<NavigationTests::T2> h2; std::cout << "before is open" <<std:: endl; std::cout << h2.isOpen() <<std:: endl; std::cout << "before reset" <<std:: endl; h2.reset(); svc->transaction().commit(); svc->session().disconnectAll(); } catch(const seal::Error& er){ std::cout << "caught seal exception " << std::endl; std::cerr << er.explainSelf(); std::cerr << std::endl; svc->transaction().commit(); svc->session().disconnectAll(); } cat->commit(); delete svc; }
jvmdiError load_new_class_versions(TRAPS) { // For consistency allocate memory using os::malloc wrapper. _k_h_new = (instanceKlassHandle *) os::malloc(sizeof(instanceKlassHandle) * _class_count); ResourceMark rm(THREAD); for (int i = 0; i < _class_count; i++) { oop mirror = JNIHandles::resolve_non_null(_class_defs[i].clazz); klassOop k_oop = java_lang_Class::as_klassOop(mirror); instanceKlassHandle k_h = instanceKlassHandle(THREAD, k_oop); symbolHandle k_name = symbolHandle(THREAD, k_h->name()); ClassFileStream st((u1*) _class_defs[i].class_bytes, _class_defs[i].class_byte_count, NULL); // Parse the stream. Handle k_loader_h(THREAD, k_h->class_loader()); Handle protection_domain; klassOop k = SystemDictionary::parse_stream(k_name, k_loader_h, protection_domain, &st, THREAD); instanceKlassHandle k_h_new (THREAD, k); if (HAS_PENDING_EXCEPTION) { if (PENDING_EXCEPTION->klass()->klass_part()->name() == vmSymbols::java_lang_UnsupportedClassVersionError()) { CLEAR_PENDING_EXCEPTION; return JVMDI_ERROR_UNSUPPORTED_VERSION; } else if (PENDING_EXCEPTION->klass()->klass_part()->name() == vmSymbols::java_lang_ClassFormatError()) { CLEAR_PENDING_EXCEPTION; return JVMDI_ERROR_INVALID_CLASS_FORMAT; } else if (PENDING_EXCEPTION->klass()->klass_part()->name() == vmSymbols::java_lang_ClassCircularityError()) { CLEAR_PENDING_EXCEPTION; return JVMDI_ERROR_CIRCULAR_CLASS_DEFINITION; } else if (PENDING_EXCEPTION->klass()->klass_part()->name() == vmSymbols::java_lang_NoClassDefFoundError()) { // The message will be "XXX (wrong name: YYY)" CLEAR_PENDING_EXCEPTION; return JVMDI_ERROR_NAMES_DONT_MATCH; } else { // Just in case more exceptions can be thrown.. return JVMDI_ERROR_FAILS_VERIFICATION; } } // See instanceKlass::link_klass_impl() { ObjectLocker ol(k_h_new, THREAD); Verifier::verify_byte_codes(k_h_new, THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return JVMDI_ERROR_FAILS_VERIFICATION; } Rewriter::rewrite(k_h_new, THREAD); // No exception can happen here } jvmdiError res = compare_class_versions(k_h, k_h_new); if (res != JVMDI_ERROR_NONE) return res; _k_h_new[i] = k_h_new; } return JVMDI_ERROR_NONE; }
void ConstantPoolCacheEntry::set_method_handle_common(constantPoolHandle cpool, Bytecodes::Code invoke_code, methodHandle adapter, Handle appendix, Handle method_type) { // NOTE: This CPCE can be the subject of data races. // There are three words to update: flags, f2, f1 (in that order). // Writers must store all other values before f1. // Readers must test f1 first for non-null before reading other fields. // Competing writers must acquire exclusive access via a lock. // A losing writer waits on the lock until the winner writes f1 and leaves // the lock, so that when the losing writer returns, he can use the linked // cache entry. Thread* THREAD = Thread::current(); ObjectLocker ol(cpool, THREAD); if (!is_f1_null()) { return; } const bool has_appendix = appendix.not_null(); const bool has_method_type = method_type.not_null(); if (!has_appendix) { // The extra argument is not used, but we need a non-null value to signify linkage state. // Set it to something benign that will never leak memory. appendix = Universe::void_mirror(); } // Write the flags. set_method_flags(as_TosState(adapter->result_type()), ((has_appendix ? 1 : 0) << has_appendix_shift) | ((has_method_type ? 1 : 0) << has_method_type_shift) | ( 1 << is_vfinal_shift) | ( 1 << is_final_shift), adapter->size_of_parameters()); if (TraceInvokeDynamic) { tty->print_cr("set_method_handle bc=%d appendix="PTR_FORMAT"%s method_type="PTR_FORMAT"%s method="PTR_FORMAT" ", invoke_code, (intptr_t)appendix(), (has_appendix ? "" : " (unused)"), (intptr_t)method_type(), (has_method_type ? "" : " (unused)"), (intptr_t)adapter()); adapter->print(); if (has_appendix) appendix()->print(); } // Method handle invokes and invokedynamic sites use both cp cache words. // f1, if not null, contains a value passed as a trailing argument to the adapter. // In the general case, this could be the call site's MethodType, // for use with java.lang.Invokers.checkExactType, or else a CallSite object. // f2 contains the adapter method which manages the actual call. // In the general case, this is a compiled LambdaForm. // (The Java code is free to optimize these calls by binding other // sorts of methods and appendices to call sites.) // JVM-level linking is via f2, as if for invokevfinal, and signatures are erased. // The appendix argument (if any) is added to the signature, and is counted in the parameter_size bits. // In principle this means that the method (with appendix) could take up to 256 parameter slots. // // This means that given a call site like (List)mh.invoke("foo"), // the f2 method has signature '(Ljl/Object;Ljl/invoke/MethodType;)Ljl/Object;', // not '(Ljava/lang/String;)Ljava/util/List;'. // The fact that String and List are involved is encoded in the MethodType in f1. // This allows us to create fewer method oops, while keeping type safety. // set_f2_as_vfinal_method(adapter()); // Store MethodType, if any. if (has_method_type) { ConstantPoolCacheEntry* e2 = cpool->cache()->find_secondary_entry_for(this); // Write the flags. e2->set_method_flags(as_TosState(adapter->result_type()), ((has_method_type ? 1 : 0) << has_method_type_shift) | ( 1 << is_vfinal_shift) | ( 1 << is_final_shift), adapter->size_of_parameters()); e2->release_set_f1(method_type()); } assert(appendix.not_null(), "needed for linkage state"); release_set_f1(appendix()); // This must be the last one to set (see NOTE above)! if (!is_secondary_entry()) { // The interpreter assembly code does not check byte_2, // but it is used by is_resolved, method_if_resolved, etc. set_bytecode_2(invoke_code); } NOT_PRODUCT(verify(tty)); if (TraceInvokeDynamic) { this->print(tty, 0); } }
jvmtiError VM_RedefineClasses::load_new_class_versions(TRAPS) { // For consistency allocate memory using os::malloc wrapper. _k_h_new = (instanceKlassHandle *) os::malloc(sizeof(instanceKlassHandle) * _class_count); ResourceMark rm(THREAD); JvmtiThreadState *state = JavaThread::current()->jvmti_thread_state(); assert(state != NULL, "JvmtiThreadState not initialized"); for (int i = 0; i < _class_count; i++) { oop mirror = JNIHandles::resolve_non_null(_class_defs[i].klass); klassOop k_oop = java_lang_Class::as_klassOop(mirror); instanceKlassHandle k_h = instanceKlassHandle(THREAD, k_oop); symbolHandle k_name = symbolHandle(THREAD, k_h->name()); ClassFileStream st((u1*) _class_defs[i].class_bytes, _class_defs[i].class_byte_count, (char *)"__VM_RedefineClasses__"); // Parse the stream. Handle k_loader_h(THREAD, k_h->class_loader()); Handle protection_domain; // Set redefined class handle in JvmtiThreadState class. // This redefined class is sent to agent event handler for class file // load hook event. state->set_class_being_redefined(&k_h); klassOop k = SystemDictionary::parse_stream(k_name, k_loader_h, protection_domain, &st, THREAD); // Clear class_being_redefined just to be sure. state->set_class_being_redefined(NULL); instanceKlassHandle k_h_new (THREAD, k); if (HAS_PENDING_EXCEPTION) { symbolOop ex_name = PENDING_EXCEPTION->klass()->klass_part()->name(); CLEAR_PENDING_EXCEPTION; if (ex_name == vmSymbols::java_lang_UnsupportedClassVersionError()) { return JVMTI_ERROR_UNSUPPORTED_VERSION; } else if (ex_name == vmSymbols::java_lang_ClassFormatError()) { return JVMTI_ERROR_INVALID_CLASS_FORMAT; } else if (ex_name == vmSymbols::java_lang_ClassCircularityError()) { return JVMTI_ERROR_CIRCULAR_CLASS_DEFINITION; } else if (ex_name == vmSymbols::java_lang_NoClassDefFoundError()) { // The message will be "XXX (wrong name: YYY)" return JVMTI_ERROR_NAMES_DONT_MATCH; } else { // Just in case more exceptions can be thrown.. return JVMTI_ERROR_FAILS_VERIFICATION; } } // All its super classes should be linked to // initialize the vtable. instanceKlassHandle super(THREAD, k_h_new->super()); if (super.not_null() && !super->is_linked()) { super->link_class(THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return JVMTI_ERROR_INTERNAL; } } // See instanceKlass::link_klass_impl() { ObjectLocker ol(k_h_new, THREAD); Verifier::verify_byte_codes(k_h_new, THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return JVMTI_ERROR_FAILS_VERIFICATION; } Rewriter::rewrite(k_h_new, THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return JVMTI_ERROR_INTERNAL; } } jvmtiError res = compare_class_versions(k_h, k_h_new); if (res != JVMTI_ERROR_NONE) return res; _k_h_new[i] = k_h_new; } return JVMTI_ERROR_NONE; }
void dopsddef(void) { int numericarg = 0; INTPTR_T dummy; INTPTR_T dummy_array[16]; int i; if (amatch("pal",3)) { if (!match("(")) error("missing ("); readstr(); /* read the label name */ addglb_far(litq2, CINT); if (!match(",")) { error("missing ',' in #defpal"); kill_line(); return; } numericarg = 0; while (!match(")")) { number(&dummy_array[numericarg]); numericarg++; if (numericarg>16) error("No more than 16 colors can be defined at once"); match(","); } ol(".data"); prefix(); outstr(litq2); outstr(":"); ot(".defpal "); for (i = 0; i < numericarg; i++) { outhexfix(dummy_array[i],3); if (i < numericarg - 1) { outstr(","); if (i == 7) { outstr(" \\\n"); ot("\t"); } } } newl(); ol(".code"); kill_line(); } else if (amatch("chr",3)) { if (!match("(")) error("missing ("); ol(".data"); readstr(); /* read the label name */ prefix(); outstr(litq2); outstr(":"); addglb_far(litq2, CINT); if (!match(",")) { error("missing ,"); kill_line(); return; } ot(".defchr "); numericarg = 0; while (!match(")")) { numericarg++; number(&dummy); switch (numericarg) { case 1: outhexfix(dummy,4); outstr(","); break; case 2: outdec(dummy); outstr(",\\"); newl(); break; case 10: outhexfix(dummy,8); break; default: outhexfix(dummy,8); outstr(",\\"); newl(); } match(","); } newl(); ol(".code"); if (numericarg!=10) error("You must enter the VRAM address, the default palette and 8 values for pattern"); kill_line(); } else if (amatch("spr",3)) { if (!match("(")) error("missing ("); ol(".data"); readstr(); /* read the label name */ prefix(); outstr(litq2); outstr(":"); addglb_far(litq2, CINT); if (!match(",")) { error("missing ,"); kill_line(); return; } ot(".defspr "); numericarg = 0; while (!match(")")) { numericarg++; number(&dummy); switch (numericarg) { case 1: outhexfix(dummy,4); outstr(","); break; case 2: outdec(dummy); outstr(",\\"); newl(); break; case 34: outhexfix(dummy,8); break; default: outhexfix(dummy,8); outstr(","); if (!(numericarg & 1)) { outstr("\\"); newl(); } } match(","); } newl(); ol(".code"); if (numericarg!=34) error("You must enter the VRAM address, the default palette and 32 values for pattern"); kill_line(); } else { error("Unknown define directive"); kill_line(); } return; }
void ConstantPoolCacheEntry::set_method_handle_common(const constantPoolHandle& cpool, Bytecodes::Code invoke_code, const CallInfo &call_info) { // NOTE: This CPCE can be the subject of data races. // There are three words to update: flags, refs[f2], f1 (in that order). // Writers must store all other values before f1. // Readers must test f1 first for non-null before reading other fields. // Competing writers must acquire exclusive access via a lock. // A losing writer waits on the lock until the winner writes f1 and leaves // the lock, so that when the losing writer returns, he can use the linked // cache entry. objArrayHandle resolved_references = cpool->resolved_references(); // Use the resolved_references() lock for this cpCache entry. // resolved_references are created for all classes with Invokedynamic, MethodHandle // or MethodType constant pool cache entries. assert(resolved_references() != NULL, "a resolved_references array should have been created for this class"); ObjectLocker ol(resolved_references, Thread::current()); if (!is_f1_null()) { return; } const methodHandle adapter = call_info.resolved_method(); const Handle appendix = call_info.resolved_appendix(); const Handle method_type = call_info.resolved_method_type(); const bool has_appendix = appendix.not_null(); const bool has_method_type = method_type.not_null(); // Write the flags. set_method_flags(as_TosState(adapter->result_type()), ((has_appendix ? 1 : 0) << has_appendix_shift ) | ((has_method_type ? 1 : 0) << has_method_type_shift) | ( 1 << is_final_shift ), adapter->size_of_parameters()); if (TraceInvokeDynamic) { ttyLocker ttyl; tty->print_cr("set_method_handle bc=%d appendix=" PTR_FORMAT "%s method_type=" PTR_FORMAT "%s method=" PTR_FORMAT " ", invoke_code, p2i(appendix()), (has_appendix ? "" : " (unused)"), p2i(method_type()), (has_method_type ? "" : " (unused)"), p2i(adapter())); adapter->print(); if (has_appendix) appendix()->print(); } // Method handle invokes and invokedynamic sites use both cp cache words. // refs[f2], if not null, contains a value passed as a trailing argument to the adapter. // In the general case, this could be the call site's MethodType, // for use with java.lang.Invokers.checkExactType, or else a CallSite object. // f1 contains the adapter method which manages the actual call. // In the general case, this is a compiled LambdaForm. // (The Java code is free to optimize these calls by binding other // sorts of methods and appendices to call sites.) // JVM-level linking is via f1, as if for invokespecial, and signatures are erased. // The appendix argument (if any) is added to the signature, and is counted in the parameter_size bits. // Even with the appendix, the method will never take more than 255 parameter slots. // // This means that given a call site like (List)mh.invoke("foo"), // the f1 method has signature '(Ljl/Object;Ljl/invoke/MethodType;)Ljl/Object;', // not '(Ljava/lang/String;)Ljava/util/List;'. // The fact that String and List are involved is encoded in the MethodType in refs[f2]. // This allows us to create fewer Methods, while keeping type safety. // // Store appendix, if any. if (has_appendix) { const int appendix_index = f2_as_index() + _indy_resolved_references_appendix_offset; assert(appendix_index >= 0 && appendix_index < resolved_references->length(), "oob"); assert(resolved_references->obj_at(appendix_index) == NULL, "init just once"); resolved_references->obj_at_put(appendix_index, appendix()); } // Store MethodType, if any. if (has_method_type) { const int method_type_index = f2_as_index() + _indy_resolved_references_method_type_offset; assert(method_type_index >= 0 && method_type_index < resolved_references->length(), "oob"); assert(resolved_references->obj_at(method_type_index) == NULL, "init just once"); resolved_references->obj_at_put(method_type_index, method_type()); } release_set_f1(adapter()); // This must be the last one to set (see NOTE above)! // The interpreter assembly code does not check byte_2, // but it is used by is_resolved, method_if_resolved, etc. set_bytecode_1(invoke_code); NOT_PRODUCT(verify(tty)); if (TraceInvokeDynamic) { ttyLocker ttyl; this->print(tty, 0); } }