The production of J/psi mesons is studied in pp collisions at root s = 7 TeV with the CMS experiment at the LHC. The measurement is based on a dimuon sample corresponding to an integrated luminosity of 314 nb(-1). The J/psi differential cross section is determined, as a function of the J/psi transverse momentum, in three rapidity ranges. A fit to the decay length distribution is used to separate the prompt from the non-prompt (b hadron to J/psi) component. Integrated over J/psi transverse momentum from 6.5 to 30 GeV/c and over rapidity in the range vertical bar y vertical bar < 2.4, the measured cross sections, times the dimuon decay branching fraction, are 70.9 +/- 2.1(stat.) +/- 3.0(syst.) +/- 7.8(luminosity) nb for prompt J/psi mesons assuming unpolarized production and 26.0 +/- 1.4(stat.) +/- 1.6(syst.) +/- 2.9(luminosity) nb for J/psi mesons from b-hadron decays.